GG Plot Flashcards
Graphing data in R
Components of a creating a plot using ggplot2
- Data (Vector or column)
- Aesthetic mappings of the data (x, y values, map variables to colors)
- At least one geometric object (type of plot or chart)
inputs for Aesthetic Mappings
ggplot(data_frame, aes(x = x_column, y = y_column)
inputs for geometric opject
geom_(point or histogram or box plot(plot inputs for bins, fill, etc)
Sample boxplot code
ggplot(family, aes( x = age, y = weight)) + geom_boxplot(color = ‘light blue’)
Sample histogram code
ggplot(mpg, aes(x = engine size, y = ..density..##Fills density of 100)) + geom_histogram(bins = 5 ##of total bins, color = ‘blue’#color of bins)
facet_wrap
Displays two histograms side by side by different variables:
ggplot(mpg, aes(x = engine size, y = ..density..##Fills density of 100)) + geom_histogram(bins = 5 ##of total bins, color = ‘blue’#color of bins) + facet_wrap(~vehicletype)