Note that there are some explanatory texts on larger screens.

plurals
  1. POSetting breakpoints for data with scale_fill_brewer() function in ggplot2
    primarykey
    data
    text
    <p>I am creating a map (choropleth) as described on the <a href="https://github.com/hadley/ggplot2/wiki/plotting-polygon-shapefiles" rel="nofollow noreferrer">ggplot2 wiki</a>. Everything works like a charm, except that I am running into an issue mapping a continuous value to the polygon fill color via the scale_fill_brewer() function.</p> <p><a href="https://stackoverflow.com/questions/5996513/change-colour-scheme-for-ggplot-geom-polygon-in-r">This question</a> describes the problem I'm having. As in the answer, my workaround has been to pre-cut my data into bins using the gtools quantcut() function:</p> <p><strong>UPDATE: This first example is actually the right way to do this</strong></p> <pre><code>require(gtools) # needed for quantcut() ... fill_factor &lt;- quantcut(fill_continuous, q=seq(0,1,by=0.25)) ggplot(mydata) + aes(long,lat,group=group,fill=fill_factor) + geom_polygon() + scale_fill_brewer(name="mybins", palette="PuOr") </code></pre> <p>This works, however, I feel like I should be able to skip the step of pre-cutting my data and do something like this with the breaks option:</p> <pre><code>ggplot(mydata) + aes(long,lat,group=group,fill=fill_continuous) + geom_polygon() + scale_fill_brewer(names="mybins", palette="PuOr", breaks=quantile(fill_continuous)) </code></pre> <p>But this doesn't work. Instead I get an error something like:</p> <blockquote> <p>Continuous variable (composite score) supplied to discrete scale_brewer.</p> </blockquote> <p>Have I misunderstood the purpose of the "breaks" option? Or is breaks broken?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    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