您好,我希望这个气泡图的图例中的气泡在图表中使用的绿色颜色着色。我想出了如何使用简单的颜色(例如橙色)自定义颜色,但我不确定如何用绿色颜色覆盖aes,或者更一般的任何调色板。
向导(size=guide_legend(override.aes= list(color=“橙色”)
# 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() 发布于 2020-03-14 03:29:03
您可以使用viridis函数将颜色(在本例中为3色)从viridis调色板传递到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()

https://stackoverflow.com/questions/60675989
复制相似问题