Get access to all lessons in this course.
Going Deeper with R
Advanced Data Wrangling and Analysis
- Importing Data
- Tidy Data
- Reshaping Data
- Dealing with Missing Data
- Changing Variable Types
- Advanced Variable Creation
- Advanced Summarizing
- Binding Data Frames
- Merging Data
- Renaming Variables
- Quick Interlude to Reorganize our Code
- Exporting Data
Advanced Data Visualization
- Data Visualization Best Practices
- Tidy Data
- Pipe Data Into ggplot
- Reorder Plots to Highlight Findings
- Line Charts
- Use Color to Highlight Findings
- Use the scales Package for Nicely Formatted Values
- Use Direct Labeling
- Use Axis Text Wisely
- Use Titles to Highlight Findings
- Use Color in Titles to Highlight Findings
- Use Annotations to Explain
- Tweak Spacing
- Customize Your Theme
- Customize Your Fonts
- Try New Plot Types
- Advanced Markdown Text Formatting
- Advanced YAML
- Inline R Code
- Making Your Reports Shine: Word Edition
- Making Your Reports Shine: HTML Edition
- Making Your Reports Shine: PDF Edition
- Other Formats
- You Did It!
Try New Plot Types
This lesson is locked
This lesson is called Try New Plot Types, part of the Going Deeper with R course. This lesson is called Try New Plot Types, part of the Going Deeper with R course.
Click on the transcript to go to that point in the video. Please note that transcripts are auto generated and may contain minor inaccuracies.
enrollment_by_race_ethnicity %>% filter(race_ethnicity == "Hispanic/Latino") %>% select(-c(race_ethnicity, number_of_students, district_id)) %>% pivot_wider(id_cols = district, names_from = year, values_from = percent_of_total_at_school) %>% clean_names() %>% slice(1:10) %>% ggplot(aes(x = x2017_2018, xend = x2018_2019, y = district, yend = district)) + geom_dumbbell(colour_x = "gray", colour = "gray", colour_xend = "blue", size_x = 3, size_xend = 1.5) + theme_student() + scale_x_continuous(label = percent_format())
Use one of the packages above to make a unique plot. For example, you might use dumbell plots in the
ggaltpackage to show change in the Hispanic/Latino population from 2017-2018 to 2018-2019 for all districts.
When you finish your plot, email it to me at [email protected]! I’d love to see what you come up with.
Heads up: You likely want to watch the solutions video because it involves reshaping the data to make it work with the
You can see all of the geoms built into ggplot here.
The documentation websites for the packages discussed in this lesson are below:
To learn more about other things that. arepossible with ggplot, check out the awesome ggplot2 GitHub repository , which has a list of a lot of other great ggplot extensions to try out!
I'd also recommend looking at the Data to Viz website , which lists various visualization options and provides sample R code for each.
Finally, if you're not already following Tidy Tuesday , check it out! Every week, a new data set is released, which people then analyze and visualize. They post their results using the #TidyTuesday hashtag. The most incredible thing is that people often post their code alongside their visualizations so you can see how they did what they did.
Three regular Tidy Tuesday contributors I'd recommend following (their work is exceptional and they always post their code) are: