0

i just need a minor tweak. I am drawing a choropleth with ggplot. Everything works fine, except one ecstatically misleading aspect: as you can see in the figure here

choropleth

ggplot picks 0 as a starting value for the shading of the provinces, while the vector of values lies between 0.331 and 0.591. I believe a starting value of, say, 300, would enhance the differences between the different provinces.

This is my code:

  ggplot(final.plot.orph, aes(x = long, y = lat, group = id, fill = CMPI)) +
  geom_polygon() + 
  coord_equal() +
  scale_fill_distiller(palette = "Blues", direction = 1) +
  theme_void() +
  theme(legend.position = "bottom",
        panel.background = element_rect(fill = NA, colour = "#cccccc"))  + 
  with(province_orph, annotate(geom = "text", x = lab_long, y = lab_lat, label = label, size = 2.5))

I guess it has something to do with the scale_fill_distiller. After looking at the documentation, I tried to include

rescale(to = c(0.300, 0.600), from = c(0, 1))

as an argument of the scale_fill_distiller line but I get an error message that says one argument (i.e. x) is missing. I also tried using . as x, but got the following error message

Error in rescale(., to = c(0.3, 0.6), from = c(0, 1)) : 
  object '.' not found

Data available here, in case of need.

Thanks!

Manolo
  • 73
  • 8
  • 1
    I don't understand why the values are 3 orders of magnitude lower then your desired starting values, but you can set scale limits bij doing for example: `scale_fill_distiller(palette = "Blues", direction = 1, limits = c(300, NA))`, wherein the `NA` indicates that the natural upper limit should be taken. – teunbrand Apr 02 '20 at 09:57
  • thanks @teunbrand that works well! not sure why they are lower, I suspect it might be from a previous choropleth, though I did not change and stored any setting there. One small edit, your code works by setting the lower limit to `0.300`, not `300`, to keep with the values of each province. Cheers! – Manolo Apr 02 '20 at 10:42

0 Answers0