我可以使用geom_point
绘制地图,该地图绘制每个点的大小,颜色和alpha随人口而变化(请参考1)。图例正确显示了与我为总体定义的每个中断相关的大小,颜色和Alpha。但是,如果我改用geom_sf
绘制点(所有其他代码相同),则图例不会正确显示。它仅显示一个矩形框,其中的线条已调整为颜色,而alpha或气泡大小没有变化(请参阅2)。有关如何解决此问题的任何想法?帖子底部的代码
# Code using geom_point
data %>%
ggplot() +
geom_sf(data = map, aes(geometry=geometry), fill='#d5d5d2', colour=NA) +
geom_point(aes(x=longitude, y=latitude, size=popM, color=popM, alpha=popM),
shape=20, stroke=FALSE) +
scale_size_continuous(name='Population (M)', trans='log',
range=c(1,12), breaks=mybreaks) +
scale_alpha_continuous(name='Population (M)', trans='log',
range=c(0.1, .9), breaks=mybreaks) +
scale_color_viridis(option="magma", trans="log", breaks=mybreaks,
name='Population (M)') +
theme_void() + coord_sf() +
guides( colour = guide_legend()) +
ggtitle('Cities With A Population Over 20 Thousand') +
theme(
legend.position = c(0.1, 0.25),
text = element_text(color = '#22211d'),
plot.background = element_rect(fill = '#f5f5f2', color = NA),
panel.background = element_rect(fill = '#f5f5f2', color = NA),
legend.background = element_rect(fill = '#f5f5f2', color = NA),
plot.title = element_text(size= 16, hjust=0.1, color = '#2e2d27',
margin = margin(b = -0.1, t = 0.4, l = 2,
unit = 'cm'),
face = 'bold'),
)
# For the second map, geom_point is replaced with this line
geom_sf(aes(geometry=geometry, size=popM, color=popM, alpha=popM),
shape=20, stroke=FALSE) +