Skip to content

Instantly share code, notes, and snippets.

@thoughtfulbloke
Created February 7, 2018 23:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save thoughtfulbloke/7dcc08f26fc6f8df3865de4e8d53a180 to your computer and use it in GitHub Desktop.
Save thoughtfulbloke/7dcc08f26fc6f8df3865de4e8d53a180 to your computer and use it in GitHub Desktop.
library(atus)
library(dplyr)
library(ggplot2)
library(ggridges)
library(viridis)
data("atusact")
data("atuscps")
data("atusresp")
actions <- c("Relaxing&Thinking", "Tobacco&Drugs", "TV&Movies", "Relgious TV",
"Listen to Radio", "Listen/Play music", "Games", "Computer non-games",
"Arts&Crafts", "Collecting", "Hobbies", "Reading", "Writing")
#from the atuact help 120300-120400 is receational activity
sports <- atusact %>% filter(tiercode > 120300, tiercode < 120350) %>%
mutate(activity = actions[tiercode-120300]) %>% select(tucaseid, activity)
atuscps %>%
select(tucaseid, age, sex) %>% inner_join(sports) %>%
ggplot(aes(x=age, y= activity,fill=floor(..x../10))) +
geom_density_ridges_gradient(rel_min_height = 0.01, colour="white") +
xlab("age of particpants") + xlim(15,86) +
scale_fill_viridis() + theme_minimal() + guides(fill=FALSE) +
ggtitle("Age distributions of recreational activity participants (source ATUS)")+
facet_wrap(~ sex, ncol=2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment