r - 调整堆叠条形图中的 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()
解决方案
你很接近,没有yticks
参数 in barplot()
,它实际上是yaxp
1。我们还=
用于函数参数和<-
函数外的赋值。
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()
推荐阅读
- node.js - 尝试使用 AWS Lambda 和 Mailgun 发送交易电子邮件时的奇怪行为
- openbravo - Openbravo:不能
- stenciljs - Stencil dev 构建样式问题
- kali-linux - 如何卸载使用 dpkg 安装的软件包
- bash - 具有无限循环的 Linux bashscript 在一段时间后停止工作
- python - 如何清除循环内运行的池使用的内存?
- python - python:访问不同模块中函数中的变量
- asp.net-core - 提供了无效的请求 URI。请求 URI 必须是绝对 URI,或者必须设置 BaseAddress。在 Blazor
- python - 迭代和更改 python numpy 矩阵列的值
- xcode - Xcode 11.1:未显示测试指标