help needed with histogram plotting

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

help needed with histogram plotting

cassie jones
Dear all,

I am trying to plot 3 histograms on the same graph using the following
command.

hist(x,xlim=c(0,100))
hist(y,add=TRUE)
hist(z,add=TRUE)

The xlim of y is c(20,21) and that of z is c(99,99.5) , whereas the variable
x has xlim at c(0.5,2). Apparently, the graph end of displaying a line only,
corresponding to each histogram due to the wide range of the xlim and
tightness of the histograms. I need to plot them on the same graph for
comparison purpose. Can anyone suggest me a better way to do it? I am
wondering if there is any command in R, where we can break the x-axis into
several parts putting a 'break' at the discontinuity..what I mean is if the
x-axis start from 0 and break at say 3, then start at 19 and break at 21 and
the last part starts at say 98. In this way, the histograms would be
prominent.

Thanks in advance.


Cassie

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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 | Threaded
Open this post in threaded view
|

Re: help needed with histogram plotting

Scott Chamberlain-3
Does this seems like a good stand in for now:

require(ggplot2)

x <- runif(100,1,2)
y <- runif(100,50,60)
z <- runif(100,99,100)

xyz <- melt(data.frame(x,y,z))

ggplot(xyz, aes(value)) +
geom_histogram() +
facet_grid(~ variable, scale="free")


On Sunday, March 6, 2011 at 9:25 PM, cassie jones wrote:

> Dear all,
>
> I am trying to plot 3 histograms on the same graph using the following
> command.
>
> hist(x,xlim=c(0,100))
> hist(y,add=TRUE)
> hist(z,add=TRUE)
>
> The xlim of y is c(20,21) and that of z is c(99,99.5) , whereas the variable
> x has xlim at c(0.5,2). Apparently, the graph end of displaying a line only,
> corresponding to each histogram due to the wide range of the xlim and
> tightness of the histograms. I need to plot them on the same graph for
> comparison purpose. Can anyone suggest me a better way to do it? I am
> wondering if there is any command in R, where we can break the x-axis into
> several parts putting a 'break' at the discontinuity..what I mean is if the
> x-axis start from 0 and break at say 3, then start at 19 and break at 21 and
> the last part starts at say 98. In this way, the histograms would be
> prominent.
>
> Thanks in advance.
>
>
> Cassie
>
>  [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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]]

______________________________________________
[hidden email] 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.