Skip to content
R for the Rest of Us Logo

Going Deeper with R

Bring it All Together (Advanced Data Visualization)

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 Community Survey
format: html
execute: 
  echo: false
  warning: false
  message: false
---


```{r}
library(tidyverse)
library(scales)
```


```{r}
coding_languages <-
  read_rds("data/coding_languages.rds")

demographics <-
  read_rds("data/demographics.rds")
```

Here is a chart showing the most common languages other than R in the survey data.

```{r}
#| fig-height: 3
coding_languages |>
  count(qcoding_languages) |>
  slice_max(
    order_by = n,
    n = 10
  ) |>
  mutate(
    top_language = case_when(
      n == max(n) ~ "Y",
      .default = "N"
    )
  ) |>
  mutate(qcoding_languages = fct_reorder(qcoding_languages, n)) |>
  mutate(n_formatted = comma(n)) |>
  ggplot(
    aes(
      x = n,
      y = qcoding_languages,
      fill = top_language,
      color = top_language
    )
  ) +
  geom_col(
    width = 0.25
  ) +
  geom_text(
    aes(
      label = n_formatted
    ),
    hjust = -0.1
  ) +
  geom_text(
    aes(
      x = 0,
      label = qcoding_languages
    ),
    hjust = 0,
    vjust = -0.5
  ) +
  scale_fill_manual(
    values = c(
      "Y" = "#6cabdd",
      "N" = "gray80"
    )
  ) +
  scale_color_manual(
    values = c(
      "Y" = "#6cabdd",
      "N" = "gray80"
    )
  ) +
  scale_x_continuous(
    expand = expansion(mult = c(0, 0.2))
  ) +
  theme_void(
    base_family = "Geist",
    base_size = 12
  ) +
  theme(
    legend.position = "none"
  )
```

Here is a chart showing the most common languages other than R in the survey data.

```{r}
coding_languages |>
  left_join(demographics, join_by(id)) |>
  group_by(qdegree) |>
  count(qcoding_languages) |>
  slice_max(
    order_by = n,
    n = 3
  ) |>
  ungroup() |>
  filter(
    qdegree %in%
      c(
        "Bachelor’s degree (e.g. BA, BS)",
        "Master’s degree (e.g. MA, MS, MEd)",
        "Doctorate (e.g. PhD, EdD)"
      )
  ) |>
  ggplot(
    aes(
      x = n,
      y = qcoding_languages
    )
  ) +
  geom_col() +
  facet_wrap(vars(qdegree), ncol = 1)
```

Learn More

A great general resource on data viz 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.

Have any questions? Put them below and we will help you out!

You need to be signed-in to comment on this post. Login.

Course Content

44 Lessons