I am new to working with generalized linear models and I'm having trouble plotting the results of a glm call with ggplot. My data contains only continuous variables: one response variable (count data - continuous) and two explanatory variables (both continuous). So, I am conducting a poisson multiple regression. I have found some examples of how to plot data and to fit the curve regarding normally distributed data. I have also found here (ggplot GLM fitted curve without interaction) an example of how to plot and fit a poisson ANCOVA model. In such a case, the explanatory variables are one categorical and one continuous, so it does not work for me.
I have data that look like this:
df<-data.frame(
p1=c(230.2, 110.1, 90.5, 100.3, 110.0, 380.4, 80.5, 60.7, 250.8, 350.2),
resp=c(31, 28, 12, 28, 18, 48, 19, 25, 28, 18),
p2=c(48, 36, 12, 168, 12, 60, 18, 39, 60, 12))
I ran a model as follows:
m <- glm(resp ~ p1*p2, family = poisson, data=df)
anova(m, test="Chi")
It returned me this:
Analysis of Deviance Table
Model: poisson, link: log
Response: resp
Terms added sequentially (first to last)
Df Deviance Resid. Df Resid. Dev Pr(>Chi)
NULL 9 33.204
p1 1 9.9623 8 23.242 0.001598 **
p2 1 7.2787 7 15.963 0.006978 **
p1:p2 1 7.7652 6 8.198 0.005326 **
So, there is an interaction between the explanatory variables (p1 and p2). My question is: how can I plot the results of this glm call using geom_smooth in ggplot, so that I can fit the curve and show the interaction between the two continuous explanatory variables? In addition, is there a better way to plot and visualize that?