ggplot2 plot without axes, legends, etc

后端 未结 8 1291
执念已碎
执念已碎 2020-11-28 18:23

I want to use bioconductor\'s hexbin (which I can do) to generate a plot that fills the entire (png) display region - no axes, no labels, no background, no nuthin\'.

相关标签:
8条回答
  • 2020-11-28 18:29
    'opts' is deprecated.
    

    in ggplot2 >= 0.9.2 use

    p + theme(legend.position = "none") 
    
    0 讨论(0)
  • 2020-11-28 18:29
    xy <- data.frame(x=1:10, y=10:1)
    plot <- ggplot(data = xy)+geom_point(aes(x = x, y = y))
    plot
    panel = grid.get("panel-3-3")
    
    grid.newpage()
    pushViewport(viewport(w=1, h=1, name="layout"))
    pushViewport(viewport(w=1, h=1, name="panel-3-3"))
    upViewport(1)
    upViewport(1)
    grid.draw(panel)
    
    0 讨论(0)
  • 2020-11-28 18:32

    Late to the party, but might be of interest...

    I find a combination of labs and guides specification useful in many cases:

    You want nothing but a grid and a background:

    ggplot(diamonds, mapping = aes(x = clarity)) + 
      geom_bar(aes(fill = cut)) + 
      labs(x = NULL, y = NULL) + 
      guides(x = "none", y = "none")
    

    You want to only suppress the tick-mark label of one or both axes:

    ggplot(diamonds, mapping = aes(x = clarity)) + 
      geom_bar(aes(fill = cut)) + 
      guides(x = "none", y = "none")
    

    0 讨论(0)
  • 2020-11-28 18:32

    Does this do what you want?

     p <- ggplot(myData, aes(foo, bar)) + geom_whateverGeomYouWant(more = options) +
     p + scale_x_continuous(expand=c(0,0)) + 
     scale_y_continuous(expand=c(0,0)) +
     opts(legend.position = "none")
    
    0 讨论(0)
  • 2020-11-28 18:33

    Re: changing opts to theme etc (for lazy folks):

    theme(axis.line=element_blank(),
          axis.text.x=element_blank(),
          axis.text.y=element_blank(),
          axis.ticks=element_blank(),
          axis.title.x=element_blank(),
          axis.title.y=element_blank(),
          legend.position="none",
          panel.background=element_blank(),
          panel.border=element_blank(),
          panel.grid.major=element_blank(),
          panel.grid.minor=element_blank(),
          plot.background=element_blank())
    
    0 讨论(0)
  • 2020-11-28 18:41

    Current answers are either incomplete or inefficient. Here is (perhaps) the shortest way to achieve the outcome (using theme_void():

    data(diamonds) # Data example
    ggplot(data = diamonds, mapping = aes(x = clarity)) + geom_bar(aes(fill = cut)) +
          theme_void() + theme(legend.position="none")
    

    The outcome is:


    If you are interested in just eliminating the labels, labs(x="", y="") does the trick:

    ggplot(data = diamonds, mapping = aes(x = clarity)) + geom_bar(aes(fill = cut)) + 
          labs(x="", y="")
    
    0 讨论(0)
提交回复
热议问题