Alter just horizontal spacing between facets (ggplot2)

后端 未结 2 501
误落风尘
误落风尘 2020-12-29 21:07

ggplot2 has the ability to change the margins between a faceted plot using the argument panel.margin in opts. This seems to change bo

相关标签:
2条回答
  • 2020-12-29 21:32

    A manual solution until this feature becomes available:

    library(grid)
    height <- 0.5 # Vertical spacing
    aux <- 1e-5 # Auxiliary number to identify 'height' among other heights
    width <- 0.1 # Desirable horizontal spacing
    
    p <- p + theme(panel.margin = unit(height + aux, "lines"))
    
    gtable <- ggplot_gtable(ggplot_build(p))
    gtable$widths[sapply(gtable$widths, '[[', 1) == height + aux][[1]][[1]] <- width
    grid.draw(gtable)
    

    enter image description here

    0 讨论(0)
  • 2020-12-29 21:38

    As of July 9th, 2015, the panel.margin.x and panel.margin.y seem to have been implemented

    p <- p + theme(panel.margin.x=unit(0.5, "lines") , panel.margin.y=unit(1,"lines"))
    

    As of December 15, 2016, 'panel.spacing' and 'panel.spacing.x' is implemented in r 3.3.2 and ggplot2 2.2.0

    p <- p + theme(panel.spacing.x=unit(0.5, "lines"),panel.spacing.y=unit(1, "lines"))
    
    0 讨论(0)
提交回复
热议问题