I'm trying to create a stacked bar graph with errorbars* using ggplot2, similar to the plot below: I've used the following code: df<-data.frame(substrate=gl(6,2,12,labels=letters[1:6]),depth=gl(2,1,12,labels=c("surf","deep")),mean=10*runif(12),err=runif(12))p<-ggplot(...
ggplot(data,aes(symbols,asset.std,label=symbols))+geom_bar(alpha=0.25)+geom_bar(aes(symbols,asset.dstd),fill="blue",alpha=0.25) If you really want stacked bars, melt the data and then plot it. library("reshape2")ggplot(melt(data,id.vars="symbols"),aes(symbols,value,fill=variable))+...
我想从快速R中创建一个像下面的代码那样的堆叠条形图: # Stacked Bar Plot with Colors and Legend counts <- table(mtcars$vs, mtcars$gear) barplot(counts, main="Car Distribution by Gears and VS", xlab="Number of Gears", col=c("darkblue","red"), legend = rownames(counts)) 然而,我不想用...
其中,x轴为分类变量treatment(Therapy/Control),y轴为受试者人数(counts),亚组为分类变量improved(None/Some/Treated)。 百分比柱状图(percent stacked barplot) # 百分比柱状图 library(scales) ggplot(mydata, aes(x = treatment, fill = improved)) + geom_bar(width = 0.3, position = "fill") + # ...
首先使用汇总统计数据初始化ggplot,指定x、y、ymin和ymax,通常指定ymin = len-sd,ymax = len+sd 来添加向下和向上的误差条(均值 ± 标准差)。如果仅需要向上的误差条而不需要向下的误差条,可设置 ymin = len ,ymax = len+sd # Initialize ggplot with data f <- ggplot( df.summary, aes(x = dose...
barplot(table3, xlab='满意度', ylab='人数', col=c('#DE2D26', '#31A354', '#3182BD'), main='(c) 垂直条形图', cex.names=1.2, cex.lab=1.2) 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. #2000个被调查者满意度的条形图 ...
`ggplot2` 是 R 语言中一个非常强大的数据可视化包,它允许用户创建各种复杂的图形。堆叠条形图(stacked bar chart)是一种常用的数据可视化方式,它可以展示每个类别中各个部分的相...
barplot(lumen, main = "stacked", xlab = "treatment", ylab = "frequency", col = c("red","yellow","green"), legend =rownames(lumen)) #分组条形图 barplot(lumen, main = "Grouped", xlab = "treatment", ylab = "frequency", col = c("red","yellow","green"), ...
分组堆积图 grouped stacked barplot library(ggplot2) library(viridis) library(hrbrthemes) specie <- c(rep("sorgho" , 3) , rep("poacee" , 3) , rep("banana" , 3) , rep("triticum" , 3) ) condition <- rep(c("normal" , "stress" , "Nitrogen") , 4) value <- abs(rnorm(12 ,...
barplot_stack.png 输入数据要求长数据,长宽数据使用reshape2转换,参考:https://cloud.tencent.com/developer/article/1369874 绘图代码如下 library(ggplot2) ## 导入数据 setwd("PATH") test <- read.csv('test.csv', header = T) ## 设置展示的顺序,不设置则默认按照首字母 ...