-
Advanced Data Wrangling
- Downloading and Importing Data
- Overview of Tidy Data
- Tidy Data Rule #1: Every Column is a Variable
- Tidy Data Rule #3: Every Cell is a Single Value
- Tidy Data Rule #2: Every Row is an Observation
- Changing Variable Types
- Dealing with Missing Data
- Advanced Summarizing
- Binding Data Frames
- Functions
- Data Merging
- Exporting Data
- Bring It All Together (Advanced Data Wrangling)
-
Advanced Data Visualization
- Best Practices in Data Visualization
- Tidy Data
- Pipe Data into ggplot
- Reorder Plots to Highlight Findings
- Line Charts
- Use Color to Highlight Findings
- Declutter
- Add Descriptive Labels to Your Plots
- Use Titles to Highlight Findings
- Use Annotations to Explain
- Tweak Spacing
- Create a Custom Theme
- Customize Your Fonts
- Try New Plot Types
- Bring it All Together (Advanced Data Visualization)
-
Quarto
- Advanced Markdown
- Advanced YAML and Code Chunk Options
- Tables
- Inline R Code
- Making Your Reports Shine: Word Edition
- Making Your Reports Shine: PDF Edition
- Making Your Reports Shine: HTML Edition
- Presentations
- Dashboards
- Websites
- Publishing Your Work
- Quarto Extensions
- Parameterized Reporting, Part 1
- Parameterized Reporting, Part 2
- Parameterized Reporting, Part 3
- Wrapping up Going Deeper with R
Going Deeper with R
Bring it All Together (Advanced Data Visualization)
This lesson is called Bring it All Together (Advanced Data Visualization), part of the Going Deeper with R course. This lesson is called Bring it All Together (Advanced Data Visualization), part of the Going Deeper with R course.
If the video is not playing correctly, you can watch it in a new window
Transcript
Click on the transcript to go to that point in the video. Please note that transcripts are auto generated and may contain minor inaccuracies.
View code shown in video
---
title: "R Survey"
author: "David Keyes"
format: html
execute:
echo: false
warning: false
message: false
output: true
editor_options:
chunk_output_type: console
---
```{r}
# Load packages
library(tidyverse)
library(janitor)
library(scales)
library(ggtext)
```
```{r}
demographics <- read_rds("data/demographics.rds")
other_coding_languages <- read_rds("data/other_coding_languages.rds")
```
Here is a data viz of the most common coding languages people say they know.
```{r}
#| fig-height: 5
update_geom_defaults(geom = "text",
aes(family = "Inter"))
other_coding_languages |>
count(qcoding_languages) |>
slice_max(order_by = n,
n = 10) |>
mutate(qcoding_languages = fct_reorder(qcoding_languages, n)) |>
mutate(n_formatted = comma(n)) |>
mutate(is_r = case_when(
qcoding_languages == "R" ~ "Y",
.default = "N"
)) |>
ggplot(aes(x = n,
y = qcoding_languages,
fill = is_r,
color = is_r)) +
geom_col(width = 0.5,
color = "transparent") +
geom_text(aes(label = n_formatted),
hjust = 1.25,
color = "white") +
geom_text(aes(x = 0,
label = qcoding_languages),
hjust = 0,
vjust = -1.5) +
labs(title = "<b style='color: #6cabdd;'>R</b> is by far the most the popular language among respondents") +
theme_void(base_family = "Inter") +
theme(legend.position = "none",
plot.title = element_markdown(margin = margin(b = 10,
unit = "pt"))) +
scale_x_continuous(expand = expansion(add = 0)) +
scale_fill_manual(values = c(
"Y" = "#6cabdd",
"N" = "grey80"
)) +
scale_color_manual(values = c(
"Y" = "#6cabdd",
"N" = "grey70"
))
```
Here is the data viz of the most common coding languages people say they know **broken out by country**.
```{r}
other_coding_languages |>
left_join(demographics,
join_by(id)) |>
count(qcoding_languages, qdegree) |>
slice_max(order_by = n,
n = 10) |>
mutate(qcoding_languages = fct_reorder(qcoding_languages, n)) |>
ggplot(aes(x = n,
y = qcoding_languages)) +
geom_col() +
theme_minimal() +
facet_wrap(vars(qdegree))
```
Learn More
Another nice example of creating a nice line plot comes from Albert Rapp's video titled Stop making messy line charts and create meaningful plots instead.
A more general resource comes from the European Union's Data Visualization Guide. It's got section on best practices (including the concepts shown in this course) and some specifics on how to implement these practices with ggplot code.
You need to be signed-in to comment on this post. Login.