I have two variables with values ranging from 1 to 10. For each variable, there are more than 30k rows, split by many countries (identified by variable “country). I need to create a combined density plot for these two variables across all these countries.
I know how to do one or other thing. To get a density plot for many different countries, I could use facet_wrap:
ggplot(df, aes(x=var1)) + geom_density() + facet_wrap(~country)
To have density plots of two different variables in the same graphic, on the other hand, I could use something like:
plot(density(df$var1)) + lines(density(df$var2))
There might be other options like ggjoy, but I couldn’t get none of them to work together with facet_wrap or find any other way to have multiple density plots for two variables together.