library(ggplot2)
Generate subplots that each display one subset of the data using
facet_grid()
facet_wrap()
ggplot(mtcars, aes(disp, mpg)) +
geom_point() +
facet_grid(. ~ cyl)
ggplot(mtcars, aes(disp, mpg)) +
geom_point() +
facet_grid(cyl ~ .)
ggplot(mtcars, aes(disp, mpg)) +
geom_point() +
facet_grid(gear ~ cyl)
ggplot(mtcars, aes(disp, mpg)) +
geom_point() +
facet_grid(cyl ~ gear)
ggplot(mtcars, aes(disp, mpg, color = factor(cyl))) +
geom_point() +
facet_grid(. ~ cyl, scales = "free")
ggplot(mtcars, aes(disp, mpg)) +
geom_point() +
facet_grid(cyl ~ gear, switch = "both")
ggplot(mtcars, aes(disp, mpg)) +
geom_point() +
facet_wrap(~cyl)
ggplot(mtcars, aes(disp, mpg)) +
geom_point() +
facet_wrap(~cyl, nrow = 2)
ggplot(mtcars, aes(disp, mpg)) +
geom_point() +
facet_wrap(~cyl, nrow = 3)
ggplot(mtcars, aes(disp, mpg)) +
geom_point() +
facet_wrap(~cyl + gear)
ggplot(mtcars, aes(disp, mpg)) +
geom_point() +
facet_wrap(c("cyl", "gear"))
ggplot(mtcars, aes(disp, mpg)) +
geom_point() +
facet_wrap(~cyl, scales = "free")