Set Axis Limits of ggplot2 Facet Plot in R (4 Examples) | Using facet_wrap & scales | Change Axes

Описание к видео Set Axis Limits of ggplot2 Facet Plot in R (4 Examples) | Using facet_wrap & scales | Change Axes

How to set the axis limits of a ggplot2 facet plot in the R programming language. More details: https://statisticsglobe.com/set-axis-...
R code of this video:


set.seed(374658) # Create example data
x <- rnorm(1000)
y <- rnorm(1000) + x^3
group <- rbinom(1000, 1, 0.1)
x[group == 1] <- x[group == 1] * 2
y[group == 1] <- y[group == 1] * 2
data <- data.frame(x, y, group)
head(data) # Print first lines of data

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

ggp <- ggplot(data, aes(x, y)) + # Default plot with facet_wrap
geom_point() +
facet_wrap(~ group)
ggp # Draw plot in RStudio

ggp + # Draw plot with free scales
facet_wrap(~ group, scales = "free")

ggp + # Draw plot with free x-axis
facet_wrap(~ group, scales = "free_x")

ggp + # Draw plot with free y-axis
facet_wrap(~ group, scales = "free_y")

ggp + # Free y-axis & manual x-axis
facet_wrap(~ group, scales = "free_y") +
coord_cartesian(xlim = c(- 10, 10))

Комментарии

Информация по комментариям в разработке