删除绘图坐标轴数值

175
我在想是否有一种方法可以摆脱r-plot图表中的坐标轴值,分别是x轴或y轴。
我知道axes=false可以摆脱整个坐标轴,但我只想去掉数字标注。
5个回答

223

如何在 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)

3
请记住,这些会删除整个坐标轴...除非您使用将线放在坐标轴位置的bty设置,否则那里什么也没有。默认值为bty='o',因此通常会在图表周围绘制一个框,以表示坐标轴的位置。但是,如果使用bty='n',则只会有漂浮在空间中的点。 - John
下一个回答由@RichieCotton更好。 - user2297550

70

使用基本图形,标准的方法是使用 axes=FALSE,然后使用 Axis(或 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))

为格点解释加一分! - Zhubarb

22

@Richie Cotton提供了一个非常好的答案。我只能补充说,这个页面提供了一些示例。尝试以下内容:

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

11

你也可以在图表内部放置标签:


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

你将会收到一个警告。我认为这是因为labels实际上是传递给plot运行的子例程(轴?)的参数。警告将弹出,因为它没有直接作为plot函数的参数。


1
将axis_colour更改为与背景相匹配,如果您正在动态修改背景,则需要同时更新axis_colour。 * 共享图片显示使用模拟数据的图形/绘图示例。
### 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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接