ggplot(aushealth, aes(x=condition, y=Population, fill=year)) +
+ geom_bar(stat="identity", position=position_dodge())
希望岁月并肩,却又重叠在一起。
Condition Year Population
Asthma 2001 10.0
Asthma 2017 13.1
Back Issue 2001 7.5
Back Issue 2017 6.3
我究竟做错了什么?
您在代码中有一些错误:
tt = "Condition Year Population
Asthma 2001 10.0
Asthma 2017 13.1
Back_Issue 2001 7.5
Back_Issue 2017 6.3"
dat <- read.table(text = tt, header = T)
ggplot(dat, aes(x=Condition, y=Population, fill=as.factor(Year))) +
geom_bar(stat="identity", position=position_dodge())
Condition
不是大写 C,也用as.factor
在Year
. 那是主要问题。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句