I have 2 datasets, called A and B. I want to compare the distribution of one common variable, called k, showing up in both dataset, but of different lengths (A contains 2000 values of k, while B has 1000, both have some N/A). So I would like to plot the distribution of A$k anf B$k in the same plot.
I have tried:
g1 <- ggplot(A, aes(x=A$k)) + geom_density()
g2 <- ggplot(B, aes(x=B$k)) + geom_density()
g <- g1 + g2
But then comes the error:
Don't know how to add o to a plot.
How can I overcome this problem?
ggplot, avoid using$. Also you should merge your data sets by either using a common ID or creating one. Or use the new data set in anaescall to ageomie inside onegeom_densityusedata=data2,aes..... egggplot(A, aes(x=k)) + geom_density()+geom_density(data=B,aes(x=k)You should however make your question reproducible.cowplot: cran.r-project.org/web/packages/cowplot/vignettes/…