Home > Software design >  Creating an editable partial effect plot in R with the gratia::draw() function that also has a rugpl
Creating an editable partial effect plot in R with the gratia::draw() function that also has a rugpl

Time:12-04

The question I have has mostly been answered by the following post: enter image description here

When I use the mydraw.gam command (see previous post) while trying to add a rug plot (see code below), this is what my plot looks like:

p<-mydraw.gam(LMB.gam)
p[[1]]    geom_rug(position = "jitter",sides="b")

enter image description here

I need some help figuring out how to properly add a rug plot to an editable gratia::draw ggplot partial effect plot that corresponds to the actual data.

Thanks!

CodePudding user response:

I would just use smooth_estimates() and its draw() method to plot a single smooth from the model. You can then add to it using standard ggplot2 functionality...

# using your data in `df`
m <- gam(X2 ~ s(X1), data = df)
sm <- smooth_estimates(m, smooth = "s(X1)")

draw(sm)  
  labs(title = "My title", y = "foo")  
  geom_rug(data = df,
           mapping = aes(x = X1),
           sides = "b",
           inherit.aes = FALSE)

produces

enter image description here

  • Related