Public Interest::Data Ethics & Practice
The Grammar of Graphcis: All data visualizations map data to aesthetic attributes (location, shape, color) of geometric objects (lines, points, bars)
Scales control the mapping from data to aesthetics and provide tools to read the plot (axes, legends). Geometric objects are drawn in a specific coordinate system.
A plot can contains statistical transformations of the data (counts, means, medians) and faceting can be used to generate the same plot for different subsets of the data.
ggplot(data, aes(x=, y=, color=, shape=, size=)) +
geom_point() # or geom_histogram() or geom_boxplot(), etc.
aes()
function maps columns of the data frame to aesthetic properties of geometric shapes to be plotted.ggplot()
defines the plot; the geoms
show the data+
For example:
ggplot(data, aes(x = var1, y = var2)) +
geom_point(aes(color = var3)) +
geom_smooth(color = "red") +
labs(title = "Helpful Title",
x = "x-axis label")
# geom_histogram(), geom_boxplot(), geom_bar(), etc.
ggplot
+ geoms
facet_wrap()
facet_grid()
coord_cartesian
allows us to zoom in on a plotcoord_flip
allows us to flip the x and y axis