I am trying to create a violin plot for a huge dataset. I got an ordinal scaled variable for age groups (10-19, 20-29, 30-39, 40-49, and so on and a nominal variable for - let's say - drug use (YES/NO), medication intake (YES/NO), alcohol intake (YES/NO), gaming > 6 hours per day (YES/NO).
My goal is to create a boxplot (with R) with Age Groups on the x-axis and the different items on the y-axis. The x-axis would look like: 10-19, 20-29, 30-39, 40-49 years old, while the y-axis is just a stacking of different items that are independent of each other.
Mainly, I am interested in how to connect the ordinal scaled variable "age groups" and one single dichotomized item "drug use". It is worth mentioning that I only want to focus on people that answered YES. Therefore I created a new subset.
My code looks like this:
drug_age <- (drug_data$age) #drug data = people that answered YES
data$age <- as.factor(data$age)
ggplot2(drug_data,aes(x=age,y=drugs,fill=drugs))+
geom_violin)
As you can tell, I am lost at this point. My variables are factorized but at this point I don't really care about code, but more about logic. My goal is to create a graphic that shows that the frequency of druge use is more common among 20-29 years olds than 10-19 years olds, for instance.
You don't have to write code for me or anything, it would just be super helpful to give me some hints.
Thank you so much for your help!
- Gertie