On 1/14/08, Erin Steiner <[EMAIL PROTECTED]> wrote:
> #After spending the entire day working on this question, I have
> decided to reach out for support:
>
> #I am trying to overlay a densityplot from one data set over a
> histogram of another, if I were to plot the two individually, they
> would look like:
>
> # data frame construction
>
> data.frame.A <- data.frame(rnorm(12*8), c(rep("one", 4), rep("two",
> 4), rep("three", 4)), c("red", "orange", "yellow", "green"))
> names(data.frame.A) <- c("vals", "factor.1", "factor.2")
> data.frame.B <- data.frame(rnorm(12*15), c(rep("one", 4), rep("two",
> 4), rep("three", 4)), c("red", "orange", "yellow", "green"))
> names(data.frame.B) <- names(data.frame.A)

The first step would be to combine the two data sources:

df.comb <- make.groups(data.frame.A, data.frame.B)

I would then just overlay two density plots:

densityplot(~vals | factor.1 * factor.2, df.comb,
            groups = which, plot.points=FALSE,
            auto.key = TRUE)

but you could do a histogram and a densityplot too:

histogram(~vals | factor.1 * factor.2, df.comb,
          type = "density",
          groups = which,
          panel = panel.superpose,
          panel.groups = function(x, group.number, col, ...) {
              if (group.number == 1)
                  panel.histogram(x, ...)
              else
                  panel.densityplot(x, ..., plot.points = FALSE)
          })

-Deepayan

______________________________________________
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