简体   繁体   中英

Change colour of bar ggplot2

I am making a bar graph trying to change the colour of my bars using this code, but it does not seem to be working. What is the problem?

ggplot(hd.m, aes(provinces, value)) +  geom_bar(aes(fill="#0072B2"), position   = "dodge", stat="identity") + scale_fill_discrete(guide=FALSE) + xlab("Provinces and Territories") + ylab("Percentage(%)") + ggtitle("Heart Disease Prevelance across Canada in 2008-2009") + theme_bw() + theme(panel.border = element_blank()) + theme(
  plot.title = element_text(size=20),
  axis.title.x = element_text(size=14),      axis.title.y = element_text(size=14)) + geom_hline(yintercept=4.7)

在此处输入图片说明

Take the fill out of the aes.

library(ggplot2)
df <- data.frame(x = c("AB","BC","MB"), y = c(3.5,3.9,4.6))

# You have:
ggplot(df, aes(x,y)) + geom_bar(aes(fill="blue"), stat="identity")

# Try:
ggplot(df, aes(x,y)) + geom_bar(fill="blue", stat="identity")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM