I have data on a variable spanning multiple years.
I want to see how the distribution has evolved over the years.
- Is there an easy way to produce a density plot for each year in single plot with different colours for each year?
Cross Validated is a question and answer site for people interested in statistics, machine learning, data analysis, data mining, and data visualization. It only takes a minute to sign up.Sign up to join this community
> my.df <- data.frame(x=rnorm(300), year=gl(3, 100, 300, labels=2000:2002)) > head(my.df) x year 1 -0.3260365 2000 2 0.5524619 2000 3 -0.6749438 2000 4 0.2143595 2000 5 0.3107692 2000 6 1.1739663 2000 > library(lattice) > densityplot(~ x, data=my.df, groups=year)
densityplot(~ x | year, data=my.df, layout=c(3,1)) (for a facetted display).
I'll assume you are using R (from previous questions). Note that this also makes your question better suited for StackOverflow.com.
As such, I remembered an answer there that could be of service to you:Q6030684.