Hi,
I was trying to overlay/combine two freqpoly plots. The sample code below
illustrates the problem. Essentially, I want to do is:
1. Have the same colour for all the lines in 'Plot 1' (and 'Plot 2').
Currently, all the lines in Plot 1 have different colours and all the lines
in Plot 2 have different colors. I'd like for all lines in Plot 1 to be
'red' and all the lines in Plot 2 to be 'black'.
2. Combine both the plots ('Plot 1' and 'Plot 2' as one combined plot -
which I attempt to do in 'Combined Plot'). However, I'm doing something
wrong because with the code for 'Combined Plot' I just get two lines.
############ sample code ############
library(ggplot2)
###### Plot 1 - normal distributions with mean = 0 ######
mat <- matrix(rnorm(10000,mean=0),1000,10)
colnames(mat) <- paste('a',1:ncol(mat),sep='')
rownames(mat) <- 1:nrow(mat)
mat2 <- melt(mat)
ggplot(mat2) + geom_freqpoly(aes(x = value,
y = ..density.., colour = X2))
###### Plot 2- normal distributions with mean = 1
tab <- matrix(rnorm(10000,mean=1),1000,10)
colnames(tab) <- paste('b',1:ncol(tab),sep='')
rownames(tab) <- 1:nrow(tab)
tab2 <- melt(tab)
ggplot(tab2) + geom_freqpoly(aes(x = value,
y = ..density.., colour = X2))
###### Combined plot
comb <- cbind(mat,tab)
comb2 <- melt(comb)
cols <-
c(rep('red',ncol(mat)*nrow(mat)),rep('black',ncol(tab)*nrow(tab)))
ggplot(comb2) + geom_freqpoly(aes(x = value,
y = ..density.., colour = cols))
################### End code ###############
Any help would be appreciated!
thanks!
[[alternative HTML version deleted]]
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.