Distribution

First, you now want to display the variable stfdem. Think briefly about how you can represent this variable and try to write the code independently. Only then look at the possible solutions.

Try it out before looking at the other tabs!

barplot <- ggplot(
  pss, 
  aes(stfdem)
) +
  geom_bar() + 
  scale_y_continuous(
    breaks = seq(
      0, 
      900,
      100
    )
  ) +
  scale_x_continuous(
    limits = c(
      -0.5, 
      10.5
    ),
    breaks = seq(
      0,
      10,
      1
    )
  ) +
  geom_text( 
    stat = "count", 
    aes(label= ..count..), 
    vjust = -0.5, 
    size = 3.5,
    color = "darkblue"
  ) +
  labs(
    x = "Zufriedenheit mit der Demkoratie", 
    y = "Häufigkeiten", 
    title = "Verteilung von stfdem")

barplot
hist <- ggplot(
  pss, 
  aes(stfdem)
) + 
  geom_histogram(
    aes(y = ..density..), 
    color = "lightgray", 
    fill = "gray",
    binwidth = 1 # zusätzliches Argument wg pseudo-metrischen Daten
  ) + 
  geom_density(
    alpha = 0.2, 
    fill = "lightblue",
    bw = 1 # zusätzliches Argument wg pseudo-metrischen Daten (bw = binwidth)
  ) +
  labs(
    x = "Zufriedenheit mit Demokratie", 
    y = "Dichte", 
    title = "Histogramm stfdem (PSS)"
  ) +
  scale_x_continuous(
    breaks = seq(
      0,
      10,
      1
    ),
    limits = c(
      -0.5, 
      10.5
    )
  )

hist

Great job if you managed to do that. Now you want to see if there are differences in the variable by gender.

Try it out before looking at the other tabs!

stfdemDistrict <- ggplot(
  pss, 
  aes(
    stfdem, 
    fill = district
  )
) +
  geom_bar(position = position_dodge()) + 
  scale_y_continuous(
    breaks = seq(
      0,
      200, 
      10
    ),
    limits = c(
      0, 
      200
    )
  ) + 
  geom_text(
    stat = "count", 
    aes(label= ..count..), 
    vjust = -1, 
    size = 3.5, 
    position = position_dodge(0.9)
  ) +
  labs(
    x = "Zufriedenheit mit Demkoratie", 
    y = "Häufigkeiten", 
    title = "Zufriedenheit mit der Demokratie nach Distrikt",
    caption = "Data: Panem Social Survey."
  ) +
  scale_fill_manual(
    name = "Distrikt", 
    values = beyonce_palette(26)
  ) +
  facet_grid(~district)

stfdemDistrict
stfdemDistrict2 <- ggplot(
  pss,
  aes(
    stfdem, 
    fill = district
  )
) +
  geom_histogram(
    aes(y = ..density..),
    alpha = 0.5, 
    binwidth = 1, 
    position = "identity"
  ) + 
  geom_density(
    alpha = 0.2,
    bw = 1
  ) +
  facet_grid(
    .~ district 
  ) + 
  scale_fill_manual(values = beyonce_palette(72)) +
  labs(
    x = "Zufriedenheit mit Demkoratie", 
    y = "Density", 
    title = "Histogramm von stfdem",
    caption = "Data: Panem Social Survey."
  ) + 
  theme(legend.position = "none")

stfdemDistrict2
stfdemDistrict3 <- ggplot(
  pss, 
  aes(
    stfdem,
    district,
    fill = district
  )
) +
  geom_density_ridges(
    scale = 0.9,
    alpha = 0.4
  ) +
  scale_x_continuous(
    limits = c(
      0,
      10
    ),
    breaks = seq(
      0,
      10,
      1
    )
  ) +
  theme_ridges() +
  theme(legend.position = "none")

stfdemDistrict3

Let’s move on to correlation visualization!