在ggplot2中合并scale_gradient和scale_size的图例

时间:2018-12-08 18:45:02

标签: r ggplot2

在此情节中:

library(ggplot2)
library(maps)
library(ggrepel)

data <- data.frame(Location=c("A", "B", "C"), Value=c(1000,1500,2000), Lat=c(20,30,40), Lon=c(10,-10,0))
mdat <- map_data('world')
ggplot() + 
  geom_polygon(dat=mdat, aes(long, lat, group=group), col="black", fill="white") +
  geom_point(data=data, aes(x=Lon, y=Lat, col=Value, size=Value)) +
  #geom_text(data=data, aes(x=Lon, y=Lat, label=Location), col="red")+
  theme_bw()+
  scale_color_gradient(limits=c(50,2000),breaks=c(50,500,1000,1500,2000),low='green', high='red')+
  scale_size(limits=c(0,2000),breaks=c(50,500,1000,1500,2000))+
  geom_label_repel(data=data, aes(x=Lon, y=Lat, label=Location), col="blue",
                   box.padding   = 0.35, 
                   point.padding = 0.5,
                   size=2.5,
                   segment.color = 'grey50') +
  theme(plot.background = element_blank(),
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        axis.text = element_blank(),
        axis.ticks = element_blank(),
        axis.title = element_blank())

我如何合并scale_color_gradient和scale_size,即图例具有不同大小和颜色的气泡?

编辑:如果不可能的话,也许可以不使用photoshop而将两个图例以一个标签并排放置?

0 个答案:

没有答案