[R] Way to rotate a histogram?
Mike Lawrence
Mike.Lawrence at dal.ca
Tue Mar 17 23:10:13 CET 2009
I actually pasted the wrong code! This attempts to replicate the
original request to replicate a JMP graphic:
library(ggplot2)
test_data<-rnorm(100,mean=10,sd=4)
a = data.frame(obs = test_data,condition = 'None')
p1 = ggplot(
data = a
,aes(
x = obs
)
)+geom_histogram(
aes(
y = ..density..
)
)+geom_density(
)+scale_x_continuous(
limits = range(a$obs)
)+opts(
panel.grid.minor = theme_blank()
,panel.grid.major = theme_blank()
,panel.background = theme_rect()
)+coord_flip(
)
p2 = ggplot(
data = a
,aes(
x = condition
,y = obs
)
)+geom_boxplot(
)+scale_y_continuous(
limits = range(a$obs)
)+scale_x_discrete(
name = ''
,labels = ''
)+opts(
panel.grid.minor = theme_blank()
,panel.grid.major = theme_blank()
,panel.background = theme_rect()
,axis.ticks = theme_blank()
,axis.text.y = theme_blank()
,axis.title.y = theme_blank()
)
p3 = ggplot(
data = a
,aes(
sample = (obs-mean(obs))/sd(obs)
)
)+stat_qq(
distribution=qnorm
)+geom_abline(
intercept=0
,slope=1
)+opts(
panel.grid.minor = theme_blank()
,panel.grid.major = theme_blank()
,panel.background = theme_rect()
,axis.ticks = theme_blank()
,axis.text.y = theme_blank()
,axis.title.y = theme_blank()
)
print(p1,vp = viewport(width = 1/3,height = 1,x = 1/3*.5,y = .5))
print(p2,vp = viewport(width = 1/3,height = 1,x = 1/3+1/3*.5,y = .5))
print(p3,vp = viewport(width = 1/3,height = 1,x = 2/3+1/3*.5,y = .5))
On Tue, Mar 17, 2009 at 6:36 PM, David Winsemius <dwinsemius at comcast.net> wrote:
> 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
>
>
--
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