【发布时间】:2015-04-22 19:49:22
【问题描述】:
给定一个没有轴的图,我想使用axis 添加一个水平轴。在左侧,您会看到给定的“基线”图,在右侧,您会看到所需的结果:
基线图是使用简单生成的
plot(1, axes = FALSE, main = "Baseline")
问题:如何生成所需的输出? (条件:在情节生成后使用axis。)
我希望在指定tick = FALSE, labels = FALSE 时得到我想要的,但这不起作用。在我的测试下面,希望不言自明:
par(mfrow = c(2,2))
plot(1, axes = FALSE, main = "Full axis")
axis(1) # axis, ticks and labels
plot(1, axes = FALSE, main = "No labels")
axis(1, labels = FALSE) # axis, ticks
plot(1, axes = FALSE, main = "No ticks (and no axis)")
axis(1, tick = FALSE) # NO axis (unexpected), labels
plot(1, axes = FALSE, main = "Nothing (instead of axis)")
axis(1, tick = FALSE, labels = FALSE) # nothing - expected: only axis without ticks, without labels
我希望最后一个图能够提供所需的输出,但根本没有绘制轴。显然,ticks = FALSE 也抑制了轴本身。
备注:“预期”图是使用
生成的plot(1, axes = FALSE, main = "Expected")
axis(1, at = c(-100, 100))
但我正在寻找一种“更清洁”的解决方案,而不是将不需要的蜱虫放在可见区域之外。
【问题讨论】:
-
box(which = "plot", lty = "solid")
-
其他解决方法是
axis(1, lwd.tick=0, labels=FALSE)、axis(1, tcl=0, labels=FALSE),分别绘制 0 宽度或 0 长度刻度。 -
@MartinMorgan:谢谢,完美运行。如果您将您的评论变成答案,我会接受。
-
另请阅读
?par,特别是您可以传递给“bty”的参数。 box(which = "plot", lty ="solid", bty ="l"),我个人建议这样做,因为你至少得到了轴。否则你会得到一个在空白 y 轴上浮动 1 的图 -
@infominer:我读过
?par,我知道bty="l",但它不仅给出了垂直轴,还给出了x和y轴。这不是我需要的(因为我需要使用axis()绘制x 轴,以便使用pos指定其位置。)我没有找到仅使用bty绘制垂直轴的方法。