When using ggplot in R, how do I remove margins surrounding the plot area?

后端 未结 4 1064
青春惊慌失措
青春惊慌失措 2020-12-10 12:23

I\'m trying to generate some fractals and have a question regarding the margins with ggplot in R. I\'m using the following code to generate the fractals.

lib         


        
4条回答
  •  一生所求
    2020-12-10 13:04

    You can also use theme_nothing() from the cowplot package:

    require(cowplot)
    qplot(1:10, (1:10)^2, geom='line') + theme_nothing() + 
      scale_x_continuous(expand=c(0,0)) +
      scale_y_continuous(expand=c(0,0)) +
      labs(x = NULL, y = NULL)
    

    Unfortunately, you still need to add labs(x = NULL, y = NULL), because there is no way in ggplot2's theme machinery to remove the axes completely. And you need to set expand=c(0,0) in the scale parameters to make sure the scale doesn't extend beyond your data range.

    Result:

    enter image description here

提交回复
热议问题