ggplot2 - Color the control group using geom_bar in R -


i have data set looks this:

a<-data.frame(strain=rep(letters[1:3], each=2),               mean=rnorm(6,0.5,0.1),               treat=rep(letters[1:2],6)) 

and plot in bar graph using ggplot, having different fill colors strain corresponding "c". don't know if have proper approach, add layer particular code, says length of fill not correct.

b <- ggplot(data=a, aes(x=factor(strain), y=mean, fill=factor(treat))) +       geom_bar(position='dodge', stat='identity') +      geom_bar(data=subset(a,a$strain=="c"), fill=c('red','blue'),               position='dodge', stat='identity') 

sorry basic question far haven't been able go around it. help!

like this?

a$treat2 <- as.character(a$treat) a$treat2[a$strain=="c"] <- paste("c",a$treat2[a$strain=="c"],sep=".")  #function create ggplot default colours ggcolours <- function(n) force(hcl(h=seq(15, 375-360/n, length=n)%%360, c=100, l=65))  b <- ggplot(data=a, aes(x=strain, y=mean, group=treat,fill=treat2)) +    geom_bar(position='dodge', stat='identity') +   #use scale_fill_manual specify colours   scale_fill_manual(values=c(ggcolours(2),"#ff0000","#0000ff"))  print(b) 

enter image description here


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -