Home > OS >  ggplot: graphic issue with multiple graphs in a column
ggplot: graphic issue with multiple graphs in a column

Time:09-30

I want to set a few graphs in one column. The graph output, also the html knit output, does not extend the view frame of all graphs. In this way, the height of each additionally added graph decreases.

Smashed graph view picture

Corresponding code:


p_load(ggplot2)
library(patchwork)
p1 <- ggplot(mpg)   
  geom_point(aes(x = displ, y = hwy))

p2 <- ggplot(mpg)   
  geom_bar(aes(x = as.character(year), fill = drv), position = "dodge")   
  labs(x = "year")

p3 <- ggplot(mpg)   
  geom_density(aes(x = hwy, fill = drv), colour = NA)   
  facet_grid(rows = vars(drv))

p4 <- ggplot(mpg)   
  stat_summary(aes(x = drv, y = hwy, fill = drv), geom = "col", fun.data = mean_se)  
  stat_summary(aes(x = drv, y = hwy), geom = "errorbar", fun.data = mean_se, width = 0.5)

p5 <- ggplot(mpg, aes(x = displ, y = hwy))   
  geom_point()

p6 <-ggplot(mpg, aes(displ, hwy, colour = class))   
  geom_point()

p1/ p2 / p3 / p4 / p5 / p6


I used Ggplot Arrange Plots Manual

How I can extend the complete view frame height for each added graph?

CodePudding user response:

If you are talking about html knit output from a .Rmd document, the way to increase the display panel for the plot is to edit the parameter of the block of r code. For example:

> ```{r, fig.height=10, fig.width=6}
> p1/ p2 / p3 / p4 / p5 / p6
> ```
  • Related