LoslegenKostenlos loslegen

Bar plots of survey-weighted means

Let's return to the dataframe of the average sleep per night by gender, which we created in Exercise 3.2. I have saved the dataframe as out in the code chunk. It's time to graph these data!

Diese Übung ist Teil des Kurses

Analyzing Survey Data in R

Kurs anzeigen

Anleitung zur Übung

  • Using geom_col(), construct a barplot where Gender is mapped to x and SleepHrsNight to y.
  • Label the y axis with "Average Nightly Sleep".

Interaktive Übung

Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.

# Compute the survey-weighted mean by Gender
out <- svyby(formula = ~SleepHrsNight, 
             by = ~Gender, 
             design = NHANES_design, 
             FUN = svymean, 
             na.rm = TRUE, 
             keep.names = FALSE)
             
# Construct a bar plot of average sleep by gender
ggplot(data = ___, mapping = aes(___)) +
  geom____() + 
  labs(___)
Code bearbeiten und ausführen