I want to create overlaped density plot. I decided to use ggplot2.
My data are in data frame formate. Here How they are look:
Ge<-data.frame(Ge)
dim(Ge)
#[1] 100 1
Ge[1:4,]
#[1] 6.005409 38.681342 102.079283 185.672611
dim(Tr)
#[1] 100 1
Tr[1:4,]
#[1] 12.8678547 1.3034715 1.1372413 0.7973491
Here is my code to create plot:
library(ggplot2)
ggplot() + geom_density(aes(x=x), colour="red", data=Tr) +
geom_density(aes(x=x), colour="blue", data=Ge)
But this is the error I get it:
Don't know how to automatically pick scale for object of type data.frame. Defaulting to continuous
Error: stat_density requires the following missing aesthetics: x
Would someone help me to solve this ?
x
the name of the column in each data frame? Try namesnames(Ge)
andnames(Tr)
. In my example I just directly referred to the column that I wanted,Ge[,1]
and that worked.