YuLab-SMU / aplot

Decorate a plot with associated information
https://yulab-smu.top/aplot
92 stars 14 forks source link

control the space of subplots #31

Closed xiangpin closed 12 months ago

xiangpin commented 12 months ago
> library(ggplot2)
Need help getting started? Try the R Graphics Cookbook:
https://r-graphics.org

> library(aplot)

> p <- ggplot(mtcars, aes(mpg, disp)) + geom_point()

> p2 <- ggplot(mtcars, aes(mpg)) +
      geom_density(fill='steelblue', alpha=.5) +
          ggfun::theme_noxaxis()

> p3 <- ggplot(mtcars, aes(x=1, y=disp)) +
      geom_boxplot(fill='firebrick', alpha=.5) +
      theme_void()

> ap <- p %>%
      insert_top(p2, height=.3) %>%
      insert_right(p3, width=.1)

> ap[2, 1] <- ap[2, 1] + theme_bw()

> ap[2, 1] <- ap[2, 1] +
              aes(color = as.factor(am)) +
              scale_color_manual(values = c('steelblue', 'darkgreen'))

> ap[1, 1] <- ap[1, 1] + theme(axis.line.x.bottom=element_line())

> ap[1,1] <- ap[1,1] + xlab(NULL)
> options(space.between.plots=5)
> ap

捕获

GuangchuangYu commented 12 months ago

next step is to let it also work with plot_list().