thank you very much David! Can I follow up with a slight complication of
this?
A 2 by 2 case, where the abline is different in each plot.

A relevant input code would be

thedataA1 <- data.frame(x1=rnorm(100,1,1),x2=rnorm(100,3,1)) #create data
thedataB1 <- data.frame(x1=rnorm(100,2,1),x2=rnorm(100,4,1)) #create data
thedataA2 <- data.frame(x1=rnorm(100,1,1),x2=rnorm(100,3,1)) #create data
thedataB2 <- data.frame(x1=rnorm(100,2,1),x2=rnorm(100,4,1)) #create data
#four different abline
v1<-mean(thedataA1$x1)
v2<-mean(thedataB1$x1)
v3<-mean(thedataA2$x1)
v4<-mean(thedataB2$x1)

thedataB1.m<-melt(thedataB1)
thedataA1.m<-melt(thedataA1)
thedataA2.m<-melt(thedataA2)
thedataB2.m<-melt(thedataB2)

# creating one density plot
densityplot(~value, thedataA1.m, groups=variable,auto.key=list(columns=2),
panel = function(x, y, ...) {
panel.densityplot(x, ...)
panel.abline(v=mean(thedataA1$x1), lty="dashed", col="red")
}
)






On 22 February 2012 13:48, David Winsemius <dwinsem...@comcast.net> wrote:

>
> On Feb 22, 2012, at 5:28 AM, josh rosen wrote:
>
>  Hi,
>>
>> I have created two separate overlapping density plots- see example code
>> below.
>> What I wish now to do is combine them into one figure where they sit side
>> by side.
>> Any help would be great!
>>
>> many thanks in advance, josh.
>>
>> #####################
>> thedataA <- data.frame(x1=rnorm(100,1,1),**x2=rnorm(100,3,1)) #create
>> data
>> thedataA.m<-melt(thedataA)
>>
>> densityplot(~value, thedataA.m, groups=variable,auto.key=list(**
>> columns=2),
>>      panel = function(x, y, ...) {
>>              panel.densityplot(x, ...)
>>              panel.abline(v=0)
>>      }
>> )
>>
>>
> The syntax for grouping (which gives theoverlaid but different colors as
> default output) and "separation" is fairly simple. Use the "|" operator for
> separated plots and the " .., groups= <var>, .."  parameter for overlaying
> results. It's only going to work easily if they are all in the same dataset.
>
> Try:
>
>  bigset <- cbind( rbind(thedataA.m, thedataB.m), ABgrp=rep(c("datA",
> "datB"), each=200) )
>  densityplot(~value|ABgrp, data=bigset, groups=variable,
> auto.key=list(columns=2),
>
>       panel = function(x, y, ...) {
>               panel.densityplot(x, ...)
>               panel.abline(v=0)   } )
>
>
> And please work on whatever practice is producing duplicate postings.
>
> --
> David.
>
>
>
>
>  thedataB <- data.frame(x1=rnorm(100,2,1),**x2=rnorm(100,4,1)) #create
>> data
>> thedataB.m<-melt(thedataA)
>>
>
> I assume that is a copy-paste-fail-to-correct error.
>
>
>> densityplot(~value, thedataB.m, groups=variable,auto.key=list(**
>> columns=2),
>>      panel = function(x, y, ...) {
>>              panel.densityplot(x, ...)
>>              panel.abline(v=0)
>>      }
>> )
>> ######################
>>
>>        [[alternative HTML version deleted]]
>>
>> ______________________________**________________
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/**listinfo/r-help<https://stat.ethz.ch/mailman/listinfo/r-help>
>> PLEASE do read the posting guide http://www.R-project.org/**
>> posting-guide.html <http://www.R-project.org/posting-guide.html>
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
> David Winsemius, MD
> West Hartford, CT
>
>

        [[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