[R] histograms embedded in a plot (as alternative to jitter)

Jim Lemon jim at bitwrit.com.au
Wed Mar 5 23:58:05 CET 2014


On 03/06/2014 12:44 AM, Bernard North wrote:
> Dear R list,
>
> I am plotting a discrete valued number on the y axis against a continuous variable on the x axis.
> To allow sample size to be viewed for the discrete groups I am using vertical jitter.
> So my code is along the lines of
> y<-rpois(500,2)
> x<-rnorm(500,y,1)
> plot(x,jitter(y))
>
> It has not been suggested that a more informative view of the sample size might be if a histogram could be inserted into the plot (instead of the jittered rows of points) for the values at each y-value
> Many thanks if anyone can think of a way to do this
>
Hi Bernard,
You can use the subplot function in the TeachingDemos package to do 
things like this.

Jim




More information about the R-help mailing list