Vin*_*der 0 r ggplot2 geom-bar
我有这样的数据集:
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))
Run Code Online (Sandbox Code Playgroud)
我想得到这个结果ggplot2:

但我只有这个
ggplot()+ geom_bar(data=comb,aes(x=nom, y=val,fill=type),stat='identity',position='dodge')
Run Code Online (Sandbox Code Playgroud)

你有什么解决办法吗?
如果您希望所有条形都具有不同的颜色,则必须使用interactionoftype和nom:
library(ggplot2)
ggplot() +
geom_bar(data = comb,aes(x = nom, y = val, fill = interaction(type, nom)),
stat = 'identity', position = 'dodge')
Run Code Online (Sandbox Code Playgroud)

| 归档时间: |
|
| 查看次数: |
2364 次 |
| 最近记录: |