Question on scales = "free_y""

33 views
Skip to first unread message

Muhuri, Pradip (SAMHSA/CBHSQ)

unread,
Sep 25, 2012, 10:51:35 PM9/25/12
to Muhuri, Pradip (SAMHSA/CBHSQ), ggp...@googlegroups.com
Hello,

I am rephrasing my question regarding scales = "free_y", which I had posted earlier. Could any one please tell me what is wrong with my code below? In my plot, I would like to have the y-axis that would vary depending on the range of the y-values in different facets.

I would appreciate receiving any tips you may provide to make the code work.

Thanks,

Pradip Muhuri

##########
p <- ggplot(dat, aes(x=Model, y=Est, ymin=LCI, ymax=UCI))+
geom_pointrange(linetype = 1,size=1.0, colour = "navyblue")+
geom_hline(aes(yintercept=1), size=1.0, colour="red", lty=2) +
facet_wrap(~ age, nrow=1, scales="free_y")+
coord_flip()+
ylim(0,6 )+
scale_fill_grey()+ theme_bw()+
xlab (" ")+
ylab("Hazards Ratio ")+

theme(text = element_text(size = 20, face = "bold"),
axis.text.x = element_text(vjust = 0, colour="black"),
axis.text.y = element_text(hjust = 1, colour="black"),
axis.title.y = element_text(size = rel(0.4), colour="black"),
axis.title.x = element_text( face = "plain"),
legend.text = element_text(size = rel(0.8), hjust = 0),
legend.position = ("none"))


print(p)
ggsave(file='c11_forest_plots_hr.png', width=11, height=7)


--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility

To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

Winston Chang

unread,
Sep 25, 2012, 10:58:52 PM9/25/12
to Muhuri, Pradip (SAMHSA/CBHSQ), ggp...@googlegroups.com
I think the problem is that scales="free" doesn't work with coord_flip. This is a limitation of ggplot2.

See here:
https://github.com/hadley/ggplot2/issues/673

 If it's very important to have free scales and use the same orientation that you're currently using, I would suggest rewriting it to not use coord_flip, by swapping the x and y variables, changing vline to hline, and replacing the pointrange with a point and a segment.

-Winston

Muhuri, Pradip (SAMHSA/CBHSQ)

unread,
Sep 27, 2012, 9:09:37 PM9/27/12
to Winston Chang, ggp...@googlegroups.com
Thanks, Winston.

Pradip
________________________________________
From: Winston Chang [winsto...@gmail.com]
Sent: Tuesday, September 25, 2012 10:58 PM
To: Muhuri, Pradip (SAMHSA/CBHSQ)
Cc: ggp...@googlegroups.com
Subject: Re: Question on scales = "free_y""

I think the problem is that scales="free" doesn't work with coord_flip. This is a limitation of ggplot2.

See here:
https://github.com/hadley/ggplot2/issues/673

If it's very important to have free scales and use the same orientation that you're currently using, I would suggest rewriting it to not use coord_flip, by swapping the x and y variables, changing vline to hline, and replacing the pointrange with a point and a segment.

-Winston

To post: email ggp...@googlegroups.com<mailto:ggp...@googlegroups.com>
To unsubscribe: email ggplot2+u...@googlegroups.com<mailto:ggplot2%2Bunsu...@googlegroups.com>
More options: http://groups.google.com/group/ggplot2

--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility

To post: email ggp...@googlegroups.com<mailto:ggp...@googlegroups.com>
To unsubscribe: email ggplot2+u...@googlegroups.com<mailto:ggplot2%2Bunsu...@googlegroups.com>
More options: http://groups.google.com/group/ggplot2

Reply all
Reply to author
Forward
0 new messages