您好,我希望此气泡图的图例中的气泡以图表中使用的翠绿颜色进行着色。我想出了如何使用简单的颜色(例如,这里的橙色)来自定义颜色,但是我不确定如何使用绿色的颜色或更笼统地覆盖任何调色板。
指南(大小= guide_legend(override.aes =列表(颜色=“橙色”)))
# Libraries
library(ggplot2)
library(dplyr)
# Get the world polygon and extract UK
library(maps)
UK <- map_data("world") %>% filter(region=="UK")
# Get a data frame with longitude, latitude, and size of bubbles (a bubble = a city)
data <- world.cities %>% filter(country.etc=="UK")
# virids package for the color palette
library(viridis)
# Do bubble map and use viridis as color palette
ggplot() +
geom_polygon(data = UK, aes(x=long, y = lat, group = group), fill="grey", alpha=0.3) +
geom_point( data=data, aes(x=long, y=lat, size=pop, color=pop)) +
scale_size_continuous(range=c(1,12)) +
scale_color_viridis(trans="log") +
guides(size=guide_legend(override.aes = list(color= "orange"))) +
theme_void() + ylim(50,59) + coord_map()
您可以使用该viridis
函数将viridis
调色板中的颜色(在这种情况下为3种颜色)传递给override.aes
喜欢橙色的人:
ggplot() +
geom_polygon(data = UK, aes(x=long, y = lat, group = group), fill="grey", alpha=0.3) +
geom_point( data=data, aes(x=long, y=lat, size = pop, color = pop)) +
scale_size_continuous(range=c(1,12)) +
scale_color_viridis(trans="log") +
guides(size=guide_legend(override.aes = list(color = viridis(3)))) +
theme_void() + ylim(50,59) + coord_map()
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句