Draw Multiple ggplot2 Plots with Consistent Width (Example) | Set Same Legend Size | cowplot Package

Published: 15 August 2022
on channel: Statistics Globe
890
28

How to create a plot composition of multiple ggplot2 graphics with the same width in the R programming language. More details: https://statisticsglobe.com/draw-mult...
R code of this video:

data <- data.frame(value = 1:3, # Create example data
group1 = LETTERS[1:3],
group2 = c("Loooooooong_A",
"Loooooooong_B",
"Loooooooong_C"))

install.packages("ggplot2") # Install & load ggplot2
library("ggplot2")

ggp1 <- ggplot(data, # Create first plot
aes(x = group1,
y = value,
fill = group1)) +
geom_bar(stat = "identity")
ggp1

ggp2 <- ggplot(data, # Create second plot
aes(x = group2,
y = value,
fill = group2)) +
geom_bar(stat = "identity")
ggp2

install.packages("cowplot") # Install cowplot package
library("cowplot") # Load cowplot

plot_grid(ggp1, ggp2, # Draw uneven grid of plots
ncol = 1)

plot_grid(ggp1, ggp2, # Draw even grid of plots
ncol = 1,
align = "v")

Follow me on Social Media:
Facebook – Statistics Globe Page:   / statisticsglobecom  
Facebook – R Programming Group for Discussions & Questions:   / statisticsglobe  
Facebook – Python Programming Group for Discussions & Questions:   / statisticsglobepython  
LinkedIn – Statistics Globe Page:   / statisticsglobe  
LinkedIn – R Programming Group for Discussions & Questions:   / 12555223  
LinkedIn – Python Programming Group for Discussions & Questions:   / 12673534  
Twitter:   / joachimschork  

Music by bensound.com


Watch video Draw Multiple ggplot2 Plots with Consistent Width (Example) | Set Same Legend Size | cowplot Package online, duration hours minute second in high quality that is uploaded to the channel Statistics Globe 15 August 2022. Share the link to the video on social media so that your subscribers and friends will also watch this video. This video clip has been viewed 890 times and liked it 28 visitors.