ggplot中的堆积条形图

红眼用户
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.factorYear. 那是主要问题。

在此处输入图片说明

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章