2014-02-05 60 views
0

多個填充顏色我有這樣的數據集:geom_bar在GGPLOT2

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)) 

我想有這個結果與ggplot2

enter image description here

但我只是有這個

ggplot()+ geom_bar(data=comb,aes(x=nom, y=val,fill=type),stat='identity',position='dodge') 

enter image description here

您有任何解決方案嗎?

回答

3

如果希望所有酒吧有不同的顏色,你必須使用的typeinteractionnom

library(ggplot2) 
ggplot() + 
    geom_bar(data = comb,aes(x = nom, y = val, fill = interaction(type, nom)), 
      stat = 'identity', position = 'dodge') 

enter image description here

相關問題