首页 > 解决方案 > 调整堆叠条形图中的 Y 刻度

问题描述

我的问题是如何将 Y 轴刻度的间隔从 0.2 更改为 0.1?我已经尝试了一切,但我非常卡住!帖子底部堆积条形图的图片

dpi=600    #pixels per square inch

A <- c(0.417, 0.583, 0.0)
B <- c(0.7143, 0.2857, 0.0)
C <- c(0.3571, 0.4286, 0.2143)
D <- c(0.2593, 0.6297, 0.111)
data <- c(A, B, C, D)

X <- matrix(data, ncol= 4, nrow=3) 
print(X)


tiff("output.tif", width=6*dpi, height=5*dpi, res=dpi)

barplot(as.matrix(X)) 
cols <- c("#999999", "#00FF00", "#FF0000")
barplot(X, col=cols, main="Association Pollution", 
        sub="Safer® Brand Natural Fungicide", xlab="Concentration",
        ylab="Ratio of Response", ytick<-seq(0.0, 1, by=0.1), las=1, 
        names=c('Control', '0.1 μL', '1 μL', '10 μL'), xlim=c(0,6))
legend("topright", inset=c(0.01, 0.01), cex=0.55, 
       c("No Response", "Correct", "Incorrect"), fill=c("#999999", "#33FF33", "#FF0000"))

dev.off()

我的条形图

标签: r

解决方案


你很接近,没有yticks参数 in barplot(),它实际上是yaxp1。我们还=用于函数参数和<-函数外的赋值。

1学分实际上是@rawr

您不需要序列,因为yaxp=c(0, 1, 10)这意味着“从 0 到 1:进行 10 次休息”。

tiff("output.tif", width=6*dpi, height=5*dpi, res=dpi)

cols <- c("#999999", "#00FF00", "#FF0000")
barplot(X, col=cols, main="Association Pollution",
        sub="Safer® Brand Natural Fungicide", xlab="Concentration",
        ylab="Ratio of Response", yaxp=c(0, 1, 10), las=1, 
        names=c('Control', '0.1 μL', '1 μL', '10 μL'), xlim=c(0, 6))
legend("topright", inset=c(0.01, 0.01), cex=0.55, 
       c("No Response", "Correct", "Incorrect"), fill=c("#999999", "#33FF33", "#FF0000"))

dev.off()

在此处输入图像描述


推荐阅读