3.1 - ggplot Introduction
package skimr to quickly view data: skim(data.name)
3 Components of Graphic
data: dataset containing variables of interest
geom: geometric object in question (what we can observe in plot - points, lines, bars)
aes: aesthetic attributes (x/y position, color, shape, size) which are mapped to variables in dataset
Mapping argument defines how variables are mapped to aesthetics of the plot. It is always defined in aes(), and x and y arguments of aes() specify which variables to map to x/y axes
define geom: geometrical object that plot uses to represent data starts with geom_
geom_bar(), geom_line(), geom_point(), geom_boxplot, geom_violin()
ggplot(data = DATA, mapping = aes(global mappings)) + geom_TYPE(args)
Adding Color and Linear Regression
geom_smooth(method = “lm”, se = FALSE)
lm is for linear regression
se = FALSE removes banded confidence interval around line of best fit
Global and Local Mappings
ggplot(data = DATA, mapping = aes(global mappings)) + geom_()
vs
ggplot(data = DATA, mapping = aes(global mappings)) + geom_(mapping = aes(local mappings))
which is helpful when adding colors, shapes, lines to graph
Labels (within labs() layer)
title = “main" title”
subtitle = “sub text”
x = “x label”
y = “y label”
Themes
r + theme_classic()