I have this kind of dataset :
comb<-data.frame(nom=c("A","B","C","A","B","C"),type=c(rep("1",3),rep("2",3)),val=c(1,3,2,3,2,2))
I Would like to have this result with ggplot2
:
But I just have this
ggplot()+ geom_bar(data=comb,aes(x=nom, y=val,fill=type),stat='identity',position='dodge')
Do you have any solution for me?
If you want all bars to have a different color, you have to use the interaction
of type
and nom
:
library(ggplot2)
ggplot() +
geom_bar(data = comb,aes(x = nom, y = val, fill = interaction(type, nom)),
stat = 'identity', position = 'dodge')
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.