在此处跟随一些代码示例 (ggplot bubble graph custom colors) 将命名列表中的颜色分配给气泡图,但无济于事。尝试从gapminder包中模拟country_colors功能。 颜色不是我提供的命名列表中所需的颜色。
df <- data.frame(
author = c("Atrhur", "Chloe", "Ernest", "Christian",
"Beth", "Wilson"),
revenue = c(13796557L, 898702L, 15049136L, 28821608L, 44409616L, 21912235L),
sold = c(492L, 62L, 548L, 38L, 182L, 879L)
)
mycolors <- structure(c("#7F3B08", "#833D07", "#873F07", "#8B4107", "#8F4407",
"#934407"), .Names = c("Atrhur", "Chloe", "Ernest", "Christian",
"Beth", "Wilson"))
p <-
ggplot(
data = df,
aes(
x = revenue,
y = sold,
label = author
)
) +
geom_point(aes(size = revenue, alpha = 0.75, fill = author)) +
scale_size_continuous(range = c(2, 20)) +
geom_text_repel(segment.color = "gray") +
theme(legend.position = "none") +
scale_fill_manual(values = mycolors)
p