首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >R;希望制作一个漂亮的分组条形图(ggplot2),其中y轴上有%,x轴上有类别(总共9个),每个类别有四个分组条形图

R;希望制作一个漂亮的分组条形图(ggplot2),其中y轴上有%,x轴上有类别(总共9个),每个类别有四个分组条形图
EN

Stack Overflow用户
提问于 2021-09-22 20:09:24
回答 1查看 30关注 0票数 0
代码语言:javascript
运行
复制
x     a       b       c       d       e         
1   0.380   45.200  3.350   0.015   -0.27
2   0.395   19.790  29.770  0.450   -0.22
3   0.235   8.215   41.355  0.190   -0.35
4-1 0.040   14.045  35.775  0.140   -0.55
4-2 0.090   6.725   42.875  0.310   -0.60
4-3 0.000   6.655   43.195  0.150   -0.71
4-4 0.040   11.375  38.370  0.210   -0.85
4-5 0.000   8.170   41.725  0.090   -0.71
5   0.000   1.545   48.610  0.070   -0.40

我尝试创建一个DF来匹配我的参数:

代码语言:javascript
运行
复制
site <- c(rep("-0.27 (site 1)" , 4) , rep("-0.22 (site 2)" , 4) , rep("-0.35 (site 3)" , 4),
      rep("-0.55 (site 4-1)" , 4), rep("-0.60 (site 4-2)" , 4) ,rep("-0.71 (site 4-3)" , 4) 
      ,rep("-0.85 (site 4-4)" , 4) ,rep("-0.71 (site 4-5)" , 4) ,rep("-0.40 (site 5)" , 4)  )

condition <- rep(c("gravier" , "sable_grossier" , "sable_fin", "vase") , 4)

#here I have a,b,c and d, but in my original df I use these names

#I am struggling with creating a vector? DF? that can match my other arguments!

value <- ?????????

ggplot(DF, aes(fill=condition, y=value, x=site)) + 
    geom_bar(position="dodge", stat="identity")

谢谢!

EN

回答 1

Stack Overflow用户

发布于 2021-09-23 16:13:52

我明白了:

代码语言:javascript
运行
复制
niv <- c(rep("-0.27 (site 1)" , 4) , rep("-0.22 (site 2)" , 4) , rep("-0.35 (site 3)" , 4) , rep("-0.55 (site 4-1)" , 4), rep("-0.60 (site 4-2)" , 4) ,rep("-0.71 (site 4-3)" , 4) ,rep("-0.85 (site 4-4)" , 4) ,rep("-0.71 (site 4-5)" , 4) ,rep("-0.40 (site 5)" , 4)  )

condition <- rep(c("gravier" , "sable_grossier" , "sable_fin", "vase") , 9)


value =  read.table("num.txt")

DF <- data.frame(niv,condition,value)

ggplot(DF, aes(fill=condition, y=V1, x=niv)) + 
geom_bar(position="dodge", stat="identity")

The graph output

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69290674

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档