Note that there are some explanatory texts on larger screens.

plurals
  1. POChange colour scheme for ggplot geom_polygon in R
    primarykey
    data
    text
    <p>I'm creating a map using the maps library and ggplot's geom_polygon. I'd simply like to change the default blue, red, purple colour scheme to something else. I'm extremely new to ggplot so please forgive if I'm just not using the right data types. Here's what the data I'm using looks like:</p> <pre><code>&gt; head(m) region long lat group order subregion Group.1 debt.to.income.ratio.mean ratio total 17 alabama -87.46201 30.38968 1 1 &lt;NA&gt; alabama 12.4059 20.51282 39 18 alabama -87.48493 30.37249 1 2 &lt;NA&gt; alabama 12.4059 20.51282 39 19 alabama -87.52503 30.37249 1 3 &lt;NA&gt; alabama 12.4059 20.51282 39 20 alabama -87.53076 30.33239 1 4 &lt;NA&gt; alabama 12.4059 20.51282 39 21 alabama -87.57087 30.32665 1 5 &lt;NA&gt; alabama 12.4059 20.51282 39 22 alabama -87.58806 30.32665 1 6 &lt;NA&gt; alabama 12.4059 20.51282 39 &gt; head(v) Group.1 debt.to.income.ratio.mean ratio region total alabama alabama 12.40590 20.51282 alabama 39 alaska alaska 11.05333 33.33333 alaska 6 arizona arizona 11.62867 25.55556 arizona 90 arkansas arkansas 11.90300 5.00000 arkansas 20 california california 11.00183 32.59587 california 678 colorado colorado 11.55424 30.43478 colorado 92 </code></pre> <p>Here's the code:</p> <pre><code>library(ggplot2) library(maps) states &lt;- map_data("state") m &lt;- merge(states, v, by="region") m &lt;- m[order(m$order),] p&lt;-qplot(long, lat, data=m, group=group, fill=ratio, geom="polygon") </code></pre> <p>I've tried the below and more:</p> <pre><code>cols &lt;- c("8" = "red","4" = "blue","6" = "darkgreen", "10" = "orange") p + scale_colour_manual(values = cols) p + scale_colour_brewer(palette="Set1") p + scale_color_manual(values=c("#CC6666", "#9999CC")) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload