What is your research question? How can you answer it?
Different kinds of plots let you answer different questions and make different comparisons
One dataset, 25 visualizations:
https://flowingdata.com/2017/01/24/one-dataset-visualized-25-ways/
Same data, (roughly) same question, a bunch of different visualizations:
https://flowingdata.com/2018/10/17/ask-the-question-visualize-the-answer/
Based on the grammar of graphics
Dataset + variables to coordinate system + geometric object = plot
Geometric objects (“geoms”) are the key piece of the plot
Everything that goes into a plot (including the “ggplot()” part itself) is a function
You can tell by the parentheses at the end
Sometimes you add options (“arguments”) in the parentheses
Sometimes you just have them at the end ()
All screenshots from “Data Visualization” cheatsheet from Rstudio at: https://www.rstudio.com/resources/cheatsheets/
Four different ways to include error bars
Line segments
Each geom has a default statistic associated with it
But you can explicitly change the statistic
How to arrange geoms that would otherwise overlap
Arguments in the geom_bar (and similar) geoms:
geom_bar(position = “dodge”)
geom_bar(position = “fill”)
geom_bar(position = “stack”)
This can replace geom_point
geom_jitter()
Add random noise on both x and y axes to avoid overplotting
Can be modified to only jitter on 1 or the other dimension:
geom_jitter(width = 0.5)
geom_jitter(height = 0.5)
Or to limit how far the jitter spreads:
coord_cartesian()
coord_fixed(ratio = x/y)
coord_flip()
coord_polar()
coord_trans(ytrans = “sqrt”)
There are a few faceting functions, but one does most of the things you will ever need: facet_grid()
facet_grid(cols = vars(X1))
facet_grid(rows = vars(X2))
facet_grid(rows = vars(X2), cols = vars(X1))
Themes are sets of changes to the overall look of the plot
You can use some built-in default themes (today), or use packaged themes that other people have made (soon) or even make your own theme (just for fun)
Stingray plot
Violin plot
Pirate ship plot
Packed bar chart
Slope graphs:
Connected scatterplot – Healy chapter 8
Scatterplots plus:
Spaghetti plots:
https://stats.idre.ucla.edu/r/faq/how-can-i-make-spaghetti-plots/
Proportions:
https://flowingdata.com/2016/09/29/quickfire-how-to-for-visualizing-proportions-in-r/
Waffle plots and swarm plots:
https://www.r-bloggers.com/how-to-make-square-pie-charts-for-infographics-in-r/
Raincloud plots:
Radial plots:
http://www.storytellingwithdata.com/blog/2019/6/28/swdchallenge-radial-data-viz
Dot plot:
https://www.r-bloggers.com/dotplot-the-single-most-useful-yet-largely-neglected-dataviz-type/
Segmented column charts:
https://www.r-bloggers.com/make-refreshing-segmented-column-charts-with-ggchicklet/
Waterfall:
Dumbbell plots:
https://www.r-bloggers.com/make-multi-point-dumbbell-plots-in-ggplot2/
Likert plots:
https://www.r-bloggers.com/likert-plots-and-grouped-likert-plots-rstats/
General links
https://r4stats.com/examples/graphics-ggplot2/
http://r-statistics.co/Top50-Ggplot2-Visualizations-MasterList-R-Code.html