Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有这种数据集:
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:
ggplot2
但我只有这个
ggplot()+ geom_bar(data=comb,aes(x=nom, y=val,fill=type),stat='identity',position='dodge')
你有什么解决办法吗?
如果您希望所有条具有不同的颜色,则必须使用interactionoftype和nom:
interaction
type
nom
library(ggplot2) ggplot() + geom_bar(data = comb,aes(x = nom, y = val, fill = interaction(type, nom)), stat = 'identity', position = 'dodge')