But you're better of fitting the model outside of ggplot2, and the
generating exactly what you want to plot. expand.grid is often
helpful in this situation.
Hadley
--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/
I tried this but this only make a model with one predictor without taking in consideration the other variables: p = ggplot(variables, aes(temperatura, tortugas)) p + stat_smooth(method="glm", family="binomial", colour="red", size = 1.2, fill = "red")stat_smooth has a formula argument, as well as passing ... to the smoothing function, so something like (untested): p + stat_smooth(method="glm", formula=tortugas ~ profundidad + fondo + temperatura, family="binomial", colour="red", size=1.2, fill="red") might work.But you're better of fitting the model outside of ggplot2, and the generating exactly what you want to plot. expand.grid is often helpful in this situation. Hadley
Thank you very much Dennis.
Suppose that I have 4 covariates
model = glm(response ~ x1 + x2 + x3 + x4, family=binomail(logit), data = mydata)
Now I would like a plot for each covariate but according to the fitted model using stat_smooth, so I need to select one variable at the time, but how I do this using stat_smooth?
The example in stat_smooth for logistic regression appear to be for a simple model (only 1 covariate), right?
Best,
Manuel
On 05/10/2010 09:45 a.m., Dennis Murphy wrote:Hi:
On Tue, Oct 5, 2010 at 4:52 AM, Manuel Spínola <mspin...@gmail.com> wrote:
Dear list members,
How can I plot a logistic model with more than one predictor in ggplot2:
Using the function glm looks like this:
model <- glm(tortugas ~ profundidad + fondo + temperatura, family=binomial(logit), data=variables)
I tried this but this only make a model with one predictor without taking in consideration the other variables:
p = ggplot(variables, aes(temperatura, tortugas))
p + stat_smooth(method="glm", family="binomial", colour="red", size = 1.2, fill = "red")
Looks like a scatterplot to me; if tortugas is the response in a glm model, it must be binary, so your plot should have varying x with (I imagine) clusters of y values at zero and one. Since you gave ggplot only one predictor, that's what it plotted :)
You haven't specified what it is that you really want. Do you want plots of predicted responses vs. each individual covariate, a surface plot of the predicted response over pairs of covariates, or something else entirely? Your data may have to be reshaped depending on your needs.
The closest ggplot2 gets to a 3D plot is geom_contour or geom_tile. If you want pseudo-3D rendering (e.g., cloud() or wireframe() in lattice), you'll have to consult other packages such as lattice, scatterplot3d, rgl and maybe iplots.
HTH,
Dennis
Best,
Manuel
--
Manuel Spínola, Ph.D.
Instituto Internacional en Conservación y Manejo de Vida Silvestre
Universidad Nacional
Apartado 1350-3000
Heredia
COSTA RICA
mspi...@una.ac.cr
mspin...@gmail.com
Teléfono: (506) 2277-3598
Fax: (506) 2237-7036
Personal website: Lobito de río
Institutional website: ICOMVIS
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: http://gist.github.com/270442
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2