geom_bar plot with position="dodge" and geom_text duplicating values
我查看了 SO,看到很多关于与条形相关的
1 2 3 4 5 6 7 | gather.iris <- iris %>% gather(key=flower_att, value=measurement, -Species) %>% mutate(sum_value=ifelse(Species=="setosa", 5, ifelse(Species=="versicolor", 7, 9))) ggplot(data=gather.iris, aes(x=Species, y=measurement, fill=flower_att)) + geom_bar(stat="identity", position="dodge") + geom_text(aes(label=sum_value), vjust=-0.5, check_overlap=T) |
1
感谢 Gregor 的快速回答。我不明白我需要为文本选择 x 和 y 值,就像我会绘图一样。这是对这个问题的一个不太好的答案。
1 2 3 4 5 6 | gather.iris <- iris %>% gather(key=flower_att, value=measurement, -Species) %>% mutate(sum_value=ifelse(Species=="setosa", 5, ifelse(Species=="versicolor", 7, 9))) ggplot(data=gather.iris, aes(x=Species, y=measurement, fill=flower_att)) + geom_bar(stat="identity", position="dodge") + geom_text(aes(y=as.numeric(Species), label=sum_value), vjust=-0.5, check_overlap=T) |