CSStat
CSStat

Reputation: 3

Can the shape of data points be changed according to group when plotting with Sjplot?

I am trying to optimize a sjPlot for black and white printing.

My plot looks at essentially numbers of parasites, depending on the amount of rain and is categorized by breeding status.

My data is broken up into groups of bachelor and breeder/territorial males.

While I can break up the prediction lines (GLMM pred models) into dashed and solid for the two groups when using "bw" for colors in the plot.model function, I cannot change the shape (or even grayscale color) of the raw data points for the two groups.

I can split the colors of the data points by group when using a different color scheme, but this distinction disappears with "bw" (all of the points are the same shade).

Key Takeaway: Is there a way to maintain a dashed and solid line distinction between two prediction lines (achieved using [colors="bw"]) and to either change the shape or color of raw data points by group in sjPlot? Thank you in advance!

I have tried using various additions to change shape; however, nothing has worked. Here are a few of the code additions to the plot that I have tried:

aes(shape=Reproductive_Status)

dot.shape="Reproductive_Status"

group="Reproductive_Status"....shape=group

Code: set up of the GlmmTMB model

strong.2.int.y<-glmmTMB(log.strongyle. 
 ~ Rainfall_2MDelay*Reproductive_Status+age_y+(
   1 | Animal_ID),data=parasites,na.action=na.exclude)

Code: plot; "aes(shape=Reproductive_Status)" does nothing to change point shape in this function unfortunately

test2.plot_strong.2.int.y.bw<-plot_model(strong.2.int.y, type ="pred", terms = c("Rainfall_2MDelay","Reproductive_Status"), 
  sort.est = NULL, rm.terms = NULL, group.terms = NULL, pred.type = "fe", 
  title = "(a)", axis.title = NULL, axis.labels = NULL, legend.title = NULL, 
  colors = "bw", show.intercept = FALSE, show.values = TRUE, show.p = F, 
  show.data = T, show.legend = TRUE, digits = 2, show.scatter=T, 
  dot.size = 2, dot.alpha=0.3,line.size = 1, vline.color = NULL, 
  aes(shape=Reproductive_Status)) 
  + labs(x=expression('Rainfall, R'[t-2]*' (mm)'), 
     y="Strongyle Count (log[x])") 
     + theme(plot.title = element_text(hjust=0.0))


plot(test2.plot_strong.2.int.y.bw,add=TRUE)

Upvotes: 0

Views: 1152

Answers (1)

Daniel
Daniel

Reputation: 7832

For marginal effects plots (i.e. when type = "pred"), sjPlot simply calls functions from ggeffects. So if you're familiar with ggplot2, I suggest you use directly ggpredict(), which returns the underlying data that is needed for plotting.

You can also try ggeffects' plot()-method, and then try to customize it. There are two vignettes describing how to customize the plots: Plotting Marginal Effects and Customize Plot Appearance.

Hope that helps.

Upvotes: 0

Related Questions