我正在使用Wes Anderson library of palettes来创建图表。这里是虚拟数据:如何在已定义的调色板中使用两次颜色?
structure(list(Question = structure(c(1L, 2L, 1L, 2L, 1L, 2L,
1L, 2L, 1L, 2L, 1L, 2L), .Label = c("One", "Two"), class = "factor"),
Agree.Disagree = structure(c(6L, 6L, 2L, 2L, 4L, 4L, 1L,
1L, 5L, 5L, 3L, 3L), .Label = c("Agree", "Disagree", "DK",
"Neither", "Strongly Agree", "Strongly Disagree"), class = "factor"),
n = c(10, 20, 50, 60, 25, 30, 45, 50, 80, 20, 15, 10), Percent = c(4,
11, 22, 32, 11, 16, 20, 26, 36, 11, 7, 5)), .Names = c("Question",
"Agree.Disagree", "n", "Percent"), row.names = c(NA, -12L), class =
"data.frame")
下面是图形代码:
library(ggplot2)
library(wesanderson)
p5<-ggplot(data=df, aes(x=Question, y=n)) +
geom_bar(aes(fill = Agree.Disagree),stat="identity") +
theme_minimal() +
ggtitle("Questions about values and attitudes") +
labs(x = "",y = "n") +
scale_fill_manual(values = wes_palette("GrandBudapest2")) +
geom_text(aes(label=Percent), vjust=2, colour="white") +
coord_flip()
p5
显然,这是行不通的。我曾经知道一个简单的解决方法,但令人沮丧的是不记得现在是什么。有任何想法吗?
没错,我觉得这是我以前那样。 –