[R] Way to rotate a histogram?

Mike Lawrence Mike.Lawrence at dal.ca
Tue Mar 17 22:14:23 CET 2009


Using ggplot2:

library(ggplot2)
test_data<-rnorm(100)
a=data.frame(obs=test_data,condition='None')
p1=qplot(
	data=a
	,x=obs
	,geom='histogram'
	)+coord_flip()
p2=qplot(
	data=a
	,y=obs
	,x=condition
	,geom='boxplot'
	)+opts(
		axis.text.y=theme_blank()
		,axis.title.y=theme_blank()
	)+coord_flip()
p3=qplot(
	sample=test_data
	,stat='qq'
	,distribution=qnorm
	)+coord_flip()

print(p1,vp=viewport(width=1,height=1/3,x=.5,y=1/3*.5))
print(p2,vp=viewport(width=1,height=1/3,x=.5,y=1/3+1/3*.5))
print(p3,vp=viewport(width=1,height=1/3,x=.5,y=2/3+1/3*.5))


On Tue, Mar 17, 2009 at 12:38 PM, Jason Rupert <jasonkrupert at yahoo.com> wrote:
>
>
> Here is what I have so far:
>> test_data<-rnorm(100)
>> par(mfrow=c(1,3)) # 3 rows by 1 columns layout of plots
>> hist(test_data)
>> boxplot(test_data)
>> qqnorm(test_data)
>
> I noticed that I can rotate a boxplot via "horizontal", but apparently "hist" does not have that functionality.
>
> I tried stacking the plots vertically:
> test_data<-rnorm(100)
> par(mfrow=c(3,1)) # 3 rows by 1 columns layout of plots
> hist(test_data)
> boxplot(test_data, horizontal=TRUE)
> qqnorm(test_data)
>
> However, I would have to rotate the QQnorm plot, which would be pretty confusing and I think non-standard.
>
> Thank you again for any feedback and insight regarding trying to reproduce the JMP figure shown at:
> http://n2.nabble.com/Can-R-produce-this-plot--td2489288.html
>
> --- On Tue, 3/17/09, Jason Rupert <jasonkrupert at yahoo.com> wrote:
>
>> From: Jason Rupert <jasonkrupert at yahoo.com>
>> Subject: Re: [R] R package to automatically produce combination plot?
>> To: R-help at r-project.org
>> Date: Tuesday, March 17, 2009, 9:39 AM
>> I guess no reply means there is not an existing package to
>> produce the plot?
>>
>> I will post the results of my script to hopefully help
>> others who are trying to formulate the same plot.
>>
>> Thanks again.
>>
>>
>> --- On Mon, 3/16/09, Jason Rupert
>> <jasonkrupert at yahoo.com> wrote:
>>
>> > From: Jason Rupert <jasonkrupert at yahoo.com>
>> > Subject: [R] R package to automatically produce
>> combination plot?
>> > To: R-help at r-project.org
>> > Date: Monday, March 16, 2009, 8:14 PM
>> > By any chance is there an R package that automatically
>> > produces the plot shown at the following link:
>> >
>> http://n2.nabble.com/Can-R-produce-this-plot--td2489288.html
>> >
>> > That is an R package to produce on plot that has the
>> > following:
>> > (a) a vertically oriented histogram,
>> > (b) associated barplot, and
>> > (c) quantile-quantile plot (Q-Q Plot).
>> >
>> > This is based on a class lecture from University of
>> > Pennsylvania:
>> > stat.wharton.upenn.edu/~mcjon/stat-431/lecture-02.pdf
>> >
>> > I am pretty confident I can put one together, but just
>> > wanted to check that there does not already exist an R
>> > package to output such a plot.
>> >
>> > Thanks again.
>> >
>> > ______________________________________________
>> > 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
>> > and provide commented, minimal, self-contained,
>> > reproducible code.
>>
>> ______________________________________________
>> 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
>> and provide commented, minimal, self-contained,
>> reproducible code.
>
> ______________________________________________
> 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
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Mike Lawrence
Graduate Student
Department of Psychology
Dalhousie University

Looking to arrange a meeting? Check my public calendar:
http://tinyurl.com/mikes-public-calendar

~ Certainty is folly... I think. ~




More information about the R-help mailing list