【发布时间】:2023-03-31 06:49:01
【问题描述】:
我想在 ggplot2 中手动为闪避的多个条形着色。我正在使用 scale_fill_manual 指定颜色,但它仍使用默认颜色,如屏幕截图所示。
library(ggplot2)
library(dplyr)
library(tidyr)
# Some fake data
by_state<- data.frame(
state=c("Florida","New York","Nebraska","Nevada","Texas"),
healthy=c(19,16,15,20,22),
danger=c(2,4,6,2,1),
warning=c(4,5,8,3,3),
stringsAsFactors = FALSE
)
by_state%>%gather(Condition,value,-state)%>%
ggplot(aes(x=state,y=value,fill=Condition))+
geom_bar(stat = "identity", position = "dodge")+
scale_colour_manual(values = c("red","blue", "orange"))
【问题讨论】: