How to draw an unbalanced grid of plots in the R programming language. More details: [ Ссылка ]
R code of this video:
set.seed(67428) # Create example data frame
data <- data.frame(x = rnorm(100),
y = rnorm(100))
head(data) # Print head of example data frame
par(mfrow = c(2, 2)) # Specify grid of plots
plot(data$x, data$y) # Draw plots
plot(data$y, type = "l")
hist(data$x)
boxplot(data$x)
mat_layout <- matrix(c(1, 1, 2, 3, 4, 4), # Specify layout matrix
nrow = 2,
byrow = TRUE)
mat_layout # Print layout matrix
layout(mat_layout) # Apply layout function
plot(data$x, data$y) # Draw plots with different sizes
plot(data$y, type = "l")
hist(data$x)
boxplot(data$x)
install.packages("ggplot2") # Install ggplot2 package
library("ggplot2") # Load ggplot2
ggp1 <- ggplot(data, aes(x, y)) + # Create ggplot2 plot objects
geom_point()
ggp2 <- ggplot(data, aes(x = 1:nrow(data), y)) +
geom_line()
ggp3 <- ggplot(data, aes(x)) +
geom_histogram()
ggp4 <- ggplot(data, aes(x)) +
geom_boxplot()
install.packages("patchwork") # Install patchwork package
library("patchwork") # Load patchwork
(ggp1 + ggp2) / # Draw grid of ggplot2 plots
(ggp3 + ggp4)
patch_design <- c(area(1, 1, 1, 2), # Specify design of grid
area(1, 3, 1, 3),
area(2, 1, 2, 1),
area(2, 2, 2, 3))
patch_design # Print design of grid
ggp1 + ggp2 + ggp3 + ggp4 + # Grid of ggplot2 plots with manual design
plot_layout(design = patch_design)
Follow me on Social Media:
Facebook – Statistics Globe Page: [ Ссылка ]
Facebook – R Programming Group for Discussions & Questions: [ Ссылка ]
Facebook – Python Programming Group for Discussions & Questions: [ Ссылка ]
LinkedIn – Statistics Globe Page: [ Ссылка ]
LinkedIn – R Programming Group for Discussions & Questions: [ Ссылка ]
LinkedIn – Python Programming Group for Discussions & Questions: [ Ссылка ]
Twitter: [ Ссылка ]
Music by bensound.com
Ещё видео!