a problem with crossbar (moving to ggplot0.9)

59 views
Skip to first unread message

Domenico Vistocco

unread,
May 3, 2012, 10:33:22 AM5/3/12
to ggp...@googlegroups.com

Dear All,

I am struggling with the ggplot2_0.9 in order to reuse my previous code. I asked Had for an help and he suggests me to post again my request to the list (trying to provide a reproducible example). Here it is. 

Sorry for posting again the question, I try to better explain my problem.


The following code worked perfectly for me on a linux system with ggplot2_0.8.5 on an older R version:


--------------------------------------------------------------------------------------

library(ggplot2)

library(MASS)


stat_sum_single <- function(fun, geom="point", colour="red", size=3, ...) {

   stat_summary(fun.y=fun, colour=colour, geom=geom, size=size, ...)

}


stat_sum_crossbar <- function(fun1, fun2, fun3, geom="crossbar", colour="blue", ...) {

   stat_summary(fun.y=fun1, fun.ymin=fun2, fun.ymax=fun3, colour=colour, geom=geom, ...)

}


carsRidotto <- subset(Cars93, Passengers %in% 4:6)

ggp <- qplot(data= carsRidotto, Passengers, Price, geom="point")

ggp2 <- ggp + stat_sum_single(mean, shape=8, size=8)

ggp2 <- ggp2 + stat_sum_single(function(x) quantile(x, 0.1), colour="orange", shape=17, size=7) +

    stat_sum_single(function(x) quantile(x, 0.9), colour="orange", shape=17, size=7)

ggp2 <- ggp2 + stat_sum_crossbar(function(x) quantile(x, 0.5),

                                 function(x) quantile(x, 0.25),

                                         function(x) quantile(x, 0.75),

                                         geom="crossbar", colour="blue", width=0.5)

ggp2


ggp3 <- ggp2 +

stat_quantile(colour="blue", size=1, linetype=2) +

stat_quantile(colour="orange", size=1, linetype="twodash",quantiles=c(0.1, 0.9)) +

stat_smooth(method=lm, se=FALSE, colour="red")

ggp3


--------------------------------------------------------------------------------


Here you can find the three resulting graphs:


http://stat.unicas.it/downloadStatUnicas/appoggio/fig-ggp.pdf

http://stat.unicas.it/downloadStatUnicas/appoggio/fig-ggp2.pdf

http://stat.unicas.it/downloadStatUnicas/appoggio/fig-ggp3.pdf


and here is my sessionInfo():


http://stat.unicas.it/downloadStatUnicas/appoggio/sessionInfo.txt



Using the last version of ggplot2 on a Mac OsX installation, I have problem with the second plot. Here is my new sessionInfo()

http://stat.unicas.it/downloadStatUnicas/appoggio/sessionInfoNew.txt


In particular here is the resulting "bad" plot:


http://stat.unicas.it/downloadStatUnicas/appoggio/bad-fig-ggp2.pdf


The third plot correctly adds the regression lines to the second plot (I think the problem lies in the stat_sum_crossbar function). Here is the "bad" third plot:


http://stat.unicas.it/downloadStatUnicas/appoggio/bad-fig-ggp3.pdf


Thanks to the help of Brian Diggs, I succeed in reproduce the ggp2 plot using the group aesthetic in the qplot, i.e. as follows:


ggp <- qplot(data= carsRidotto, Passengers, Price, geom="point", group=Passengers)


but using such change I am not more able to reproduce the third plot.


I really appreciate any suggestion.


Ciao,

domenico

adam.l...@pnc.com

unread,
May 3, 2012, 11:17:39 AM5/3/12
to Domenico Vistocco, ggp...@googlegroups.com
Hi Domenico,

This works. The group aesthetic fixes it. This works:

ggplot(carsRidotto,aes(Passengers,Price))+
geom_point()+
stat_summary(fun.y ="mean",colour="red",size=4,shape=8,geom="point")+
stat_summary(fun.y = function(x) quantile(x,.9), colour="orange", shape=17, size=7, geom="point")+
stat_summary(fun.y = function(x) quantile(x,.1), colour="orange", shape=17, size=7, geom="point")+

stat_summary(aes(Passengers,Price,group=Passengers),fun.y = function(x) quantile(x,.5), fun.ymax = function(x) quantile(x,.75)
                ,fun.ymin = function(x) quantile(x,.25)
                ,width=0.5,geom="crossbar",colour="blue")+

stat_quantile(colour="blue", size=1, linetype=2) +
stat_quantile(colour="orange", size=1, linetype="twodash",quantiles=c(0.1, 0.9)) +
stat_smooth(method=lm, se=FALSE, colour="red")


Adam Loveland


From: Domenico Vistocco <domenico...@gmail.com>
To: ggp...@googlegroups.com
Date: 05/03/2012 10:33 AM
Subject: a problem with crossbar (moving to ggplot0.9)
Sent by: ggp...@googlegroups.com


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


The contents of this email are the property of PNC. If it was not addressed to you, you have no legal right to read it. If you think you received it in error, please notify the sender. Do not forward or copy without permission of the sender. This message may contain an advertisement of a product or service and thus may constitute a commercial electronic mail message under US Law. The postal address for PNC is 249 Fifth Avenue, Pittsburgh, PA 15222. If you do not wish to receive any additional advertising or promotional messages from PNC at this e-mail address, click here to unsubscribe. https://pnc.p.delivery.net/m/u/pnc/uni/p.asp
By unsubscribing to this message, you will be unsubscribed from all advertising or promotional messages from PNC. Removing your e-mail address from this mailing list will not affect your subscription to alerts, e-newsletters or account servicing e-mails.


Domenico Vistocco

unread,
May 3, 2012, 1:35:48 PM5/3/12
to ggp...@googlegroups.com, Domenico Vistocco
Dear Alan,
thanks for the suggestions: I used the group aesthetic in the qplot call and not in the stat_summary call.
I will try to adapt my code using your tip.

Thanks a lot,
domenico



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



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

Reply all
Reply to author
Forward
0 new messages