# [R] Way to rotate a histogram?

David Winsemius dwinsemius at comcast.net
Tue Mar 17 22:36:34 CET 2009

```Nice work, Mike. Actually I think he was looking for it done this way.

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()
)
p3=qplot(
sample=test_data
,stat='qq'
,distribution=qnorm
)

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

Perhaps with a red line through the hinge points. And probably need to
get the axes aligned proerly but it's very close.

--
david Winsemius

On Mar 17, 2009, at 5:14 PM, Mike Lawrence wrote:

> 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))

David Winsemius, MD
Heritage Laboratories
West Hartford, CT

```