Reputation: 197
I want my three-way interaction to look as closely as possible to my two-way interaction plot. Basically the same, just with two facets (called panels in my example). I would love to continue to use sjplot
with plot_model
. However, as soon as I pass any aesthetic argument to the threewayplot I get "Error in plot_model(threeway, type = "int", title = "The threeway plot that does not work", :
non-numeric argument to binary operator". And when I pass any of the theme parts it is just NULL.
Any ideas for any way to solve this, please?
So, I created the following MWE:
library(sjPlot)
library(ggplot)
data("mtcars")
mydf <- mtcars
mydf$high <- ifelse(mydf$mpg >= 20, 1, 0)
mydf$gear <- as.factor(mydf$gear)
mydf$am <- as.factor(mydf$am)
twoway <- glm(high ~ am*gear, data = mydf, family = "binomial")
plot_model(twoway, type = "int", title = "My fancy twoway plot", show.legend = TRUE,
transform = "plogis", show.values = TRUE,
dot.size = 5, line.size = 1.5, value.offset = 0,
colors = c( "#333333", "#666666","black")) +
scale_shape_manual(values = c( 15,16, 17)) +
aes(color=group, shape = group) +
labs(shape = "Cool group", color = "Cool group")+
theme_sjplot() +
theme(strip.background = element_blank(),
panel.grid.minor = element_blank(),
panel.grid.major.x = element_blank(),
panel.border = element_blank(),
axis.title.y = element_blank(),
legend.position = "bottom"
)
## Threeway
mydf$panelvar <- ifelse(mydf$carb > 3, "Panel Left", "Panel Right")
mydf$panelvar <- as.factor(mydf$panelvar)
threeway <- glm(high ~ panelvar*gear*am, data = mydf, family = "binomial")
plot_model(threeway, type = "int", title = "My sad threeway plot which works", show.legend = TRUE,
transform = "plogis", show.values = TRUE,
dot.size = 5, line.size = 1.5, value.offset = 0,
colors = c( "#333333", "#666666","black"))
plot_model(threeway, type = "int", title = "The threeway plot that does not work", show.legend = TRUE,
transform = "plogis", show.values = TRUE,
dot.size = 5, line.size = 1.5, value.offset = 0,
colors = c( "#333333", "#666666","black"))+
scale_shape_manual(values = c( 15,16, 17)) +
aes(color=group, shape = group) +
labs(shape = "Cool group", color = "Cool group") +
theme_sjplot() +
theme(strip.background = element_blank(),
panel.grid.minor = element_blank(),
panel.grid.major.x = element_blank(),
panel.border = element_blank(),
axis.title.y = element_blank(),
legend.position = "bottom"
)
Thanks in advance!
Upvotes: 0
Views: 111