ggplot2: Overlay density plots R -
i want overlay few density plots in r , know there few ways that, don't work me reason or ('sm' library doesn't install , i'm noob enough not understand of code). tried plot , par use qplot since has more configuration options.
i have data saved in form
library(ggplot2) x <- read.csv("clipboard", sep="\t", header=false) x v1 v2 v3 1 34 23 24 2 32 12 32 and create 3 overlaid plots values v1, v2 , v3 using or tones of grey fill in or using dotlines or similar legend. can guys me?
thank you!
generally ggplot , multiple variables need convert long format wide. think can done without way package meant work
here solution, generated data (3 normal distributions centered around different points). did histograms , boxplots in case want those. alpha parameters controls degree of transparency of fill, if use color instead of fill outlines
x <- data.frame(v1=rnorm(100),v2=rnorm(100,1,1),v3=rnorm(100,0,2)) library(ggplot2);library(reshape2) data<- melt(x) ggplot(data,aes(x=value, fill=variable)) + geom_density(alpha=0.25) ggplot(data,aes(x=value, fill=variable)) + geom_histogram(alpha=0.25) ggplot(data,aes(x=variable, y=value, fill=variable)) + geom_boxplot() 
Comments
Post a Comment