[R] ggplot2 stat_smooth

Nathan Pace n.l.pace at utah.edu
Thu Jun 30 00:51:51 CEST 2016


I appreciate the pointers.

I am using ggplot2 2.1.0, but I was looking at the wrong version of the web page example documentation.

The easiest way is to define the function

binomial_smooth <- function(...) {
  geom_smooth(method = "glm", method.args = list(family = "binomial"), ...)
}



And then call

ggplot(data = SSI.dt, aes(x = elapsed, y = 1 - control)) + geom_point() +

binomial_smooth()

Everything is now working smoothly.


Nathan
 





-----Original Message-----
From: David Winsemius <dwinsemius at comcast.net>
Date: Wednesday, June 29, 2016 at 16:10
To: Nathan L Pace <n.l.pace at utah.edu>
Cc: "r-help at r-project.org" <r-help at r-project.org>
Subject: Re: [R] ggplot2 stat_smooth

>
>> On Jun 29, 2016, at 2:17 PM, Nathan Pace <n.l.pace at utah.edu> wrote:
>> 
>> I want to add a logistic plot to data.
>> 
>> My call to ggplot is:
>> 
>> 
>> ggplot(data = SSI.dt, aes(x = elapsed, y = 1 - control)) + geom_point() +
>> stat_smooth(method = 'glm', family = binomial) +
>> xlab('Surgery Duration (min)') + ylab('Probability SSI') +
>> labs(title = 'THA Surgical Site Infections')
>> ggsave(filename = 'Plots/SSI.Duration.pdf’)
>> 
>> An error message is returned: Unknown parameters: family
>
>So you would have naturally looked at the acceptable arguments for the function, right?
>
>> 
>> Removing “family = binomial” returns a straight line with points appropriately placed on y = 0 and y = 1.
>> 
>> I found some previous messages on markmail that listed my call as the correct syntax structure.
>
>Perhaps they referred to older versions of the function.
>
>Looking at:
>
>?stat_smooth
>
> The current help page implements this by creating a helper function, binomial_smooth,  but using its example of the needed arguments I did just try:
>
>... + stat_smooth(method = 'glm', method.args = list(family = "binomial"))
>
>
>With success.
>
>-- 
>David.
>> 
>> I’d appreciate thoughts/pointers.
>> 
>> 
>> Nathan
>> 
>> -- 
>> Nathan Pace, MD, MStat
>> Department of Anesthesiology
>> University of Utah
>> 801.581.6393
>> n.l.pace at utah.edu
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> ______________________________________________
>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> 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.
>
>David Winsemius
>Alameda, CA, USA
>


More information about the R-help mailing list