Hi,

Here is the corrected code:

library(ggplot2)
ids <- paste('id_',1:3,sep='')
before <- sample(9)
after <- sample(1:10,9)
dat <- as.matrix(cbind(before,after))
rownames(dat) <- rep(ids,3)
position <- c(rep(10,3),rep(13,3),rep(19,3))

mdat <- cbind(melt(dat),position)
colnames(mdat) <- c('ID','Treatment','value','position')

ggplot(mdat, aes(position, value)) + geom_point(aes(colour = Treatment)) +
        geom_rug(subset = .(position < 14),aes(y=NULL),color="orange") + 
        geom_rug(subset = .(position > 14),aes(y=NULL),color="black") 



Alternatively, how do I add a second legend in ggplot2?

thanks!



________________________________
 From: John Kane <jrkrid...@inbox.com>
To: Brian Smith <bsmith030...@gmail.com>; r-help@r-project.org 
Sent: Wednesday, June 6, 2012 3:06 PM
Subject: Re: [R] ggplot2: legend for geom_rug() ..?

What is X2? 

code not running at the moment 

John Kane
Kingston ON Canada


> -----Original Message-----
> From: bsmith030...@gmail.com
> Sent: Wed, 6 Jun 2012 11:52:25 -0400
> To: r-help@r-project.org
> Subject: [R] ggplot2: legend for geom_rug() ..?
> 
> Hi,
> 
> I was trying to make another legend for the rug plot. Sample code:
> 
> 
> library(ggplo2)
> ids <- paste('id_',1:3,sep='')
> before <- sample(9)
> after <- sample(1:10,9)
> dat <- as.matrix(cbind(before,after))
> rownames(dat) <- rep(ids,3)
> position <- c(rep(10,3),rep(13,3),rep(19,3))
> 
> mdat <- cbind(melt(dat),position)
> 
> ggplot(mdat, aes(position, value)) + geom_point(aes(colour = X2)) +
>         geom_rug(subset = .(position < 14),aes(y=NULL),color="orange") +
>         geom_rug(subset = .(position > 14),aes(y=NULL),color="black")
> 
> 
> 
> 
> This gives the plot correctly, but how can I add another legend that
> would
> give some more information on the rugplot (e.g. that 'orange' line =
> 'London', and 'black' line = 'NYC')?
> 
> thanks!!
> 
>     [[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help@r-project.org 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.

____________________________________________________________
GET FREE SMILEYS FOR YOUR IM & EMAIL - Learn more at 
http://www.inbox.com/smileys
[[elided Yahoo spam]]
®, Google Talk™ and most webmails

______________________________________________
R-help@r-project.org 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.
        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org 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.

Reply via email to