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

后端 未结 4 1063
青春惊慌失措
青春惊慌失措 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:09

    I was able to get rid of the white border by setting negative plot margins and setting the axis titles to NULL. I've marked the edits in the code below.

    p = ggplot(data=df, aes(V1, V2, color=cl[V3]))+ 
      geom_point() + 
      theme(panel.background=element_blank(), 
            panel.grid.major=element_blank(), 
            panel.grid.minor=element_blank(), 
            panel.margin = unit(c(0, 0, 0, 0), "cm"),       
            axis.ticks=element_blank(), 
            axis.text.x=element_blank(), 
            axis.text.y=element_blank(), 
            axis.title.x=element_blank(), 
            axis.title.y=element_blank(),
            plot.background = element_rect(fill = "transparent",colour = NA),
            plot.margin = unit(c(-1, -1.2, -1.2, -1.5), "cm"),  # Edited code
            legend.position = 'none') +
      labs(x=NULL, y=NULL) # New code
    

提交回复
热议问题