我在R中使用了以下代码来生成此图:
x <- c(0.916, 0.815, 0.101, -0.029, -0.166, 0.949, 0.073, -0.054, 1.006)
y <- c(3.91, 5.17, 1.08, 1.28, 1.01, 4.37, 3.97, 0.77, 4.52)
sd <- c(0.35, 2.26, 0.17, 0.08, 0.27, 0.49, 0.65, 0.12, 1.45)
windows()
plot(x,y, ylim=c(0, 8), xlim=c(-0.4, 1.2), pch=19, cex.axis=0.8,
cex.lab=0.9, xlab="Male/Female expression ratio (log)",
ylab="Z/W expression ratio in females", las=1)
for (i in 1:9) {
up <- y[i] + sd[i]
low <- y[i] - sd[i]
segments(x[i], low, x[i], up)
segments(x[i]-0.02, up, x[i]+0.02, up)
segments(x[i]-0.02, low, x[i]+0.02, low)
}
我的问题是我如何摆脱两个顶轴和右轴并且只保留左下轴?
答案 0 :(得分:5)
如果您想保持盒状外观而不是“自由浮动”轴,请在bty ="l"
命令中添加plot
(小写L)。
导致:
plot(x, y, ylim=c(0, 8), xlim=c(-0.4, 1.2), pch=19, cex.axis=0.8,
cex.lab=0.9, xlab="Male/Female expression ratio (log)",
ylab="Z/W expression ratio in females", las=1, bty = "l")
这样只会删除上框和右框。
另请参阅?par
编辑:
看看您的图表和您的计算似乎,您想要绘制特定组的平均值,然后还显示一些标准偏差。在这种情况下,我建议查看boxplot()
命令,它将使用您的原始数据为您执行此操作。
见?boxplot
答案 1 :(得分:1)
您还可以尝试在绘图命令中添加frame = FALSE
:
plot(x, y, ylim=c(0, 8), xlim=c(-0.4, 1.2), pch=19, cex.axis=0.8,
cex.lab=0.9, xlab="Male/Female expression ratio (log)",
ylab="Z/W expression ratio in females", las=1, frame = FALSE)
答案 2 :(得分:0)
@ r0bert&amp; @CarlosV提供了很好的答案。还有另外一个选项:您可以使用参数axes=FALSE
来抑制轴,然后使用?axis构建自己的轴,这可以让您更好地控制axes。这是一些示例代码(作为奖励,我说明@thelatemail关于segment()
的矢量化版本的评论):
plot(x, y, axes=FALSE, ylim=c(0, 8), xlim=c(-0.4, 1.2), pch=19,
cex.axis=0.8, cex.lab=0.9, xlab="Male/Female expression ratio (log)",
ylab="Z/W expression ratio in females")
axis(side=1, cex.axis=0.8, cex.lab=0.9)
axis(side=2, cex.axis=0.8, cex.lab=0.9, las=1)
segments(x, y-sd, x, y+sd)
segments(x-0.02, y+sd, x+0.02, y+sd)
segments(x-0.02, y-sd, x+0.02, y-sd)