Remove plot axis values

前端 未结 5 1409
后悔当初
后悔当初 2020-12-04 07:52

I was just wondering if there is a way to get rid of axis values, either the x-axis or y-axis respectively, in an r-plot graph.

I know that axes = false

相关标签:
5条回答
  • 2020-12-04 08:31

    Remove numbering on x-axis or y-axis:

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

    If you want to remove the labels as well:

    plot(1:10, xaxt='n', ann=FALSE)
    plot(1:10, yaxt='n', ann=FALSE)
    
    0 讨论(0)
  • 2020-12-04 08:33

    you can also put labels inside plot:

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

    you'll get a warning. i think this is because labels is actually a parameter that's being passed down to a subroutine that plot runs (axes?). the warning will pop up because it wasn't directly a parameter of the plot function.

    0 讨论(0)
  • 2020-12-04 08:41

    @Richie Cotton has a pretty good answer above. I can only add that this page provides some examples. Try the following:

    x <- 1:20
    y <- runif(20)
    plot(x,y,xaxt = "n")
    axis(side = 1, at = x, labels = FALSE, tck = -0.01)
    
    0 讨论(0)
  • 2020-12-04 08:54

    Using base graphics, the standard way to do this is to use axes=FALSE, then create your own axes using Axis (or axis). For example,

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

    The lattice equivalent is

    library(lattice)
    xyplot(y ~ x, scales=list(alternating=0))
    
    0 讨论(0)
  • 2020-12-04 08:54

    Change the axis_colour to match the background and if you are modifying the background dynamically you will need to update the axis_colour simultaneously. * The shared picture shows the graph/plot example using mock data ()

    ### 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)
    

    0 讨论(0)
提交回复
热议问题