用三个措施分组的Barplot
我想通过Excel生成R中的以下graphics。
CSV文件具有以下内容:
> myd type am tae tac 1 kA 81.73212 73.07151 26.92849 2 kI 78.87324 84.50704 15.49296 3 kL 82.52184 69.91262 30.08738 4 kS 82.67147 69.31411 30.68589 5 sA 81.67176 73.31295 26.68705 6 sI 79.54135 81.83460 18.16540 7 sL 81.58485 73.66061 26.33939 8 sS 82.09616 71.61536 28.38464
以下R代码在y轴上创build,但我也想添加tae
和tac
。
ggplot(myd, aes(x=type, y=am)) + geom_bar(stat="identity")
你知道我怎么可以在R中添加这个像在Excel图中一样吗?
require(reshape2) myd_molten <- melt(data = myd, id.vars = "type") require(ggplot2) ggplot(myd_molten, aes(x = type, y = value, fill=variable)) + geom_bar(stat="identity", position=position_dodge())+ coord_flip()
尝试
library(tidyr) library(dplyr) library(ggplot2) gather(myd, Var, Val, am:tac) %>% ggplot(., aes(x=type, y=Val))+ geom_bar(aes(fill=Var), position='dodge', stat='identity')+ coord_flip()