sinhrks / ggfortify

Define fortify and autoplot functions to allow ggplot2 to handle some popular R packages.
Other
527 stars 65 forks source link

autoplot for glm() does not work with two column response variable #136

Closed andbeck closed 7 years ago

andbeck commented 7 years ago

binomial glm() models are often fit with a two column response variable. autoplot for these models is failing. Here is a reproducible example.

library(ggfortify)
data(menarche)
glm.out <- glm(cbind(Menarche, Total-Menarche) ~ Age, family=binomial(logit), data=menarche)
autoplot(glm.out) # fails 
#Error: Each variable must be a 1d atomic vector or list. 
#Problem variables: 'cbind(Menarche, Total - Menarche)'

# works fine
par(mfrow = c(2,2))
plot(glm.out)
sinhrks commented 7 years ago

Thx for the report. Current impl doesn't handle the case when a response is a matrix. Will check to fix it.

andbeck commented 7 years ago

Super. Thanks. We use ggfortify a lot with teaching (and in our book, Getting Started with R).

terrytangyuan commented 7 years ago

@andbeck Thanks for the support! Could you link me to the book just for my curiosity?

andbeck commented 7 years ago

Hey - the book is here:

https://global.oup.com/ukhe/product/getting-started-with-r-9780199601622?cc=gb&lang=en&

However, it's the second edition, coming in the new year, where we've shifted to ggplot and dplyr, and thus take advantage of ggfortify - particularly autoplot() - to keep things looking good! @GSwithR on twitter has the running commentary/updates, and www.r4all.org is the website.

andbeck commented 7 years ago

Thanks for this. Nice work and much appreciated.