0

If I have a facet grid with 1 row and 2 columns, they are each the same width and height. How do I reduce the size of the right facet so that the left is more dominant?

This is my current illustration:

library(tidyverse)
#create some data
set.seed(20181022)
data <- data.frame(x = letters[ceiling(runif(100, 0, 10))],y =  runif(100),stringsAsFactors = FALSE)
#duplicate the data and add an indicator for the Plot Type
data <- data %>%
bind_rows(data) %>%
mutate(PlotType = rep(c('a','b'), each = nrow(data)))
#Facet by the plot type and subset each geom (I have made some changes)
data %>%
ggplot(aes(x, y)) +
facet_grid(.~PlotType, scales = "free")+
geom_boxplot(data = filter(data, PlotType == 'a')) +
geom_bar(data = filter(data, PlotType == 'b'), stat = "identity")+
coord_flip()
  • 1
    Is this what you are looking for: https://stackoverflow.com/questions/49110877/how-to-adjust-facet-size-manually ? – MartineJ Dec 18 '19 at 14:14
  • 1
    Setting `space = "free"` in `facet_grid` will automatically adjust the size to the range of the data. If you want custom sizes not based on data, then I think MartineJ's link is a good duplicate. – Gregor Thomas Dec 18 '19 at 14:16
  • @MartineJ I tried the answer in the link but I can't seem to find the correct widths for the panel of interest. I have added code to illustrate – Vykta Wakandigara Dec 18 '19 at 14:23
  • You can use a package like [`cowplot`](https://cran.r-project.org/web/packages/cowplot/) or [`patchwork`](https://github.com/thomasp85/patchwork) if you're trying to align different plots. That might be useful particularly since your facets have different geom types anyway – camille Dec 18 '19 at 15:01
  • I agree with @camille. Patchwork is really nice (I do not know cowplot that well). You could also use gridExtra::grid.arrange with a layout_matrix for two separate plots. – MartineJ Dec 18 '19 at 19:11

0 Answers0