简体   繁体   中英

Changing the labels on ggplot legend

I'm using ggplot so I can get a gradient onto a map to show data over a large scale. There are points between 0 and 35,000 to be visualised. I have got this to work, but the legend is automatically showing labels for every 10,000.

目前的传说

Ideally I want the legend to show the maximum amount, so probably it would just show 0 at the bottom and 35,000 at the top. Is this doable?

My ggplot code is below if this helps.

ggplot() +
  geom_map(data = datafile, aes(map_id = Health_Board, fill = datafile$"2007"), map = Scot) +
  geom_polygon(data = Scot, aes(x = long, y = lat, group = group), colour = "gray", fill = NA) +
  expand_limits(x = Scot$long, y = Scot$lat) +
  scale_fill_gradient(low = ("lightyellow"), high = ("red"), limits = c(0,35000)) +
  ggtitle("2007") +
  coord_fixed(1.2) +
  theme(axis.text.x = element_blank(), axis.text.y = element_blank(), 
    axis.ticks = element_blank(), axis.title.x = element_blank(), 
    axis.title.y = element_blank(), 
    panel.grid.major = element_blank(), panel.grid.minor = element_blank(), 
    panel.border = element_blank(), panel.background = element_blank(),
    legend.title = element_text(face = "bold"),
    plot.title = element_text(face = "bold", hjust = 0.5))

You can include the "breaks" argument. Like this:

scale_fill_gradient(low = ("lightyellow"), high = ("red"),
                        breaks=c(min(lat),max(lat)),
                        limits = c(0,35000)) +

If you want more, its possible to include the "labels" argument.

scale_fill_gradient(low = ("lightyellow"), high = ("red"),
                        breaks=c(min(lat),max(lat)),
                        labels=c("Minimum","Maximum"),
                        limits = c(0,35000)) +

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM