更改R中绘图上条形的颜色

library(ggplot2)

df <- data.frame(trt=c("TAVERN","Long Term Care","Grocery Store","Restaurant"),outcome=c("a","b","c","d"))

ggplot(df,aes(trt,outcome)) + 
  geom_col() +
  geom_point(colour = 'red') +
  ggtitle("Failing rate in different facility types") + 
  labs(x="Facility type",y="Failing rate") + 
  theme(panel.background = element_blank()) +
  scale_color_manual(values = c("purple","green","red","orange"))

我尝试手动更改ggplot中的颜色。

更改R中绘图上条形的颜色

但是我没有这样做。真的很困惑。

问题。如何依次设置ggplot()函数的参数 改变条形的颜色?

since1129 回答:更改R中绘图上条形的颜色

我假设您想更改条形的颜色。然后,您需要指定fill的{​​{1}}选项。

geom_col

或者,您可以设置library(ggplot2) df <- data.frame(trt=c("TAVERN","Long Term Care","Grocery Store","Restaurant"),outcome=c("a","b","c","d")) ggplot(df,aes(trt,outcome)) + geom_col(fill=c("purple","green","red","orange")) + geom_point(colour = 'red') + ggtitle("Failing rate in different facility types") + labs(x="Facility type",y="Failing rate") + theme(panel.background = element_blank()) 美观。请注意,fill用于内部。 fill用于边界。

colour
本文链接:https://www.f2er.com/3098965.html

大家都在问