In this module, we will learn to
library(ggplot2)
library(dplyr)
library(tidyr)p <- ggplot(mtcars) +
geom_point(aes(disp, mpg))
pp + theme(axis.title.x = element_text(color = "red", size = 10))p + theme(axis.text.x = element_text(color = "red", size = 10))p + theme(axis.text = element_text(color = "red", size = 10, face = "italic"))p + theme(axis.ticks = element_line(color = 'blue', size = 1.25, linetype = 2),
axis.ticks.length = unit(1, "cm"))p + theme(axis.line = element_line(color = 'red', size = 1.5, linetype = 3))p <- ggplot(mtcars) +
geom_point(aes(disp, mpg, color = factor(cyl), shape = factor(gear)))
pp + theme(legend.background = element_rect(fill = 'gray', linetype = 3,
color = "black"))p + theme(legend.margin = margin(4, 8, 4, 8))p + theme(legend.spacing = unit(1.5, "cm"))p + theme(legend.key = element_rect(fill = 'red'),
legend.key.size = unit(0.4, "cm"))p + theme(legend.text = element_text(color = 'green', face = 'italic'))p + theme(legend.title = element_text(color = 'blue', face = 'bold'),
legend.title.align = 0.1)p + theme(legend.position = "top")p + theme(legend.direction = "horizontal")p + theme(legend.box = "horizontal",
legend.box.background = element_rect(fill = "gray"),
legend.box.spacing = unit(1, "cm"), legend.box.just = "left",
legend.box.margin = margin(4, 8, 4, 8))p <- ggplot(mtcars) +
geom_point(aes(disp, mpg))
pp + theme(panel.background = element_rect(fill = 'gray'))p + theme(panel.border = element_rect(fill = NA, color = 'blue',
linetype = 1, size = 2))p + theme(panel.grid = element_line(color = 'blue', linetype = 2, size = 0.5))p + theme(panel.grid.major.x = element_line(color = 'blue',
linetype = 2, size = 0.5))p + theme(panel.grid.minor.y = element_line(color = 'red',
linetype = 3, size = 0.2))p <- ggplot(mtcars) +
geom_point(aes(disp, mpg)) +
ggtitle('Theme Modification')
pp + theme(plot.background = element_rect(color = 'blue',
fill = '#4682B4'))p + theme(plot.title = element_text(color = 'red'))p + theme(plot.margin = unit(c(1, 1, 1, 1), "cm"))p <- ggplot(mtcars) +
geom_point(aes(disp, mpg)) +
facet_grid(~cyl)
pp + theme(strip.background = element_rect(color = 'red',
fill = '#4682B4'))p + theme(strip.text = element_text(face = 'italic', size = 8,
color = 'red'))ggplot(mtcars) +
geom_point(aes(disp, mpg)) +
theme_bw()ggplot(mtcars) +
geom_point(aes(disp, mpg)) +
theme_gray()ggplot(mtcars) +
geom_point(aes(disp, mpg)) +
theme_light()ggplot(mtcars) +
geom_point(aes(disp, mpg)) +
theme_minimal()ggplot(mtcars) +
geom_point(aes(disp, mpg)) +
theme_dark()ggplot(mtcars) +
geom_point(aes(disp, mpg)) +
theme_classic()ggplot(mtcars) +
geom_point(aes(disp, mpg)) +
theme_void()To do: - add intro slide - section for axis, legend, panel, plot area, facets and themes