删除绘图轴值

我只是想知道是否有办法去掉一个 r 图中的轴值,分别是 x 轴和 y 轴。

我知道 axes = false将摆脱整个轴,但我只想摆脱编号。

445170 次浏览

使用基础图形,标准的方法是使用 ax = FALSE,然后使用 Axis (或轴)创建您自己的轴。比如说,

x <- 1:20
y <- runif(20)
plot(x, y, axes=FALSE, frame.plot=TRUE)
Axis(side=1, labels=FALSE)
Axis(side=2, labels=FALSE)

格的等价物是

library(lattice)
xyplot(y ~ x, scales=list(alternating=0))

删除 x 轴或 y 轴上的编号:

plot(1:10, xaxt='n')
plot(1:10, yaxt='n')

如果你也想移除这些标签:

plot(1:10, xaxt='n', ann=FALSE)
plot(1:10, yaxt='n', ann=FALSE)

@ Richie Cotton 上面有个不错的答案。我只能补充说,这个 呼叫提供了一些示例。试试以下方法:

x <- 1:20
y <- runif(20)
plot(x,y,xaxt = "n")
axis(side = 1, at = x, labels = FALSE, tck = -0.01)

你也可以在小区内贴上标签:

plot(spline(sub$day, sub$counts), type ='l', labels = FALSE)

你会得到警告的。我认为这是因为 label 实际上是一个参数,它被传递给一个绘图运行的子程序(轴?).警告将会弹出,因为它不是 plot 函数的直接参数。

改变的轴 _ 颜色匹配的背景,如果你正在修改的背景动态,你将需要更新的轴 _ 颜色同时进行。 * 共享图片显示了使用模拟数据()的图形/绘图示例

### Main Plotting Function ###
plotXY <- function(time, value){


### Plot Style Settings ###


### default bg is white, set it the same as the axis-colour
background <- "white"


### default col.axis is black, set it the same as the background to match
axis_colour <- "white"


plot_title <- "Graph it!"
xlabel <- "Time"
ylabel <- "Value"
label_colour <- "black"
label_scale <- 2
axis_scale <- 2
symbol_scale <- 2
title_scale <- 2
subtitle_scale <- 2
# point style 16 is a black dot
point <- 16
# p - points, l - line, b - both
plot_type <- "b"


plot(time, value, main=plot_title, cex=symbol_scale, cex.lab=label_scale, cex.axis=axis_scale, cex.main=title_scale, cex.sub=subtitle_scale, xlab=xlabel, ylab=ylabel, col.lab=label_colour, col.axis=axis_colour, bg=background, pch=point, type=plot_type)
}


plotXY(time, value)

enter image description here