[R] Adding a Rotated Density Plot to an Existing Plot

Rory Winston rory.winston at gmail.com
Sun Jun 8 14:52:37 CEST 2008


Thanks Jim! Thats just what I want.

Cheers
Rory

jim holtman wrote:
> I forgot to make sure the axis ranges were the same:
>  
> x <- rnorm(1000)
> x <- x + exp(-x/2)
> layout(matrix(rep(c(1,1,2), 2), 2, 3, byrow=TRUE))
> boxplot(x, ylim=c(0.5,4))
> rug(jitter(x), side=2)
> y <- density(x)
> plot(y$y, y$x, type='l',ylim=c(0.5,4))
>
>
> On Sun, Jun 8, 2008 at 7:07 AM, Rory Winston <rory.winston at gmail.com 
> <mailto:rory.winston at gmail.com>> wrote:
>
>     Hi
>
>     Consider the following graph:
>
>     x <- rnorm(1000)
>     x <- x + exp(-x/2)
>     layout(matrix(rep(c(1,1,2), 2), 2, 3, byrow=TRUE))
>     boxplot(x)
>     rug(jitter(x), side=2)
>     plot(density(x))
>
>
>     What I would really like to do is to have the density plot rotated
>     by 90 degrees so that I can see it line up with the rug plot on
>     the side axis. I cant seem to do this. I have seen references to
>     the grid package and tried some examples, but I cant seem to get
>     it to play well with the boxplot. Does anyone know how I can do this?
>
>     Cheers
>     Rory
>
>     ______________________________________________
>     R-help at r-project.org <mailto:R-help at 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
>     <http://www.r-project.org/posting-guide.html>
>     and provide commented, minimal, self-contained, reproducible code.
>
>
>
>
> -- 
> Jim Holtman
> Cincinnati, OH
> +1 513 646 9390
>
> What is the problem you are trying to solve?



More information about the R-help mailing list