pbreheny / visreg

Visualization of regression functions
http://pbreheny.github.io/visreg/
61 stars 18 forks source link

shape-coded dots #105

Closed felixpleiva closed 1 year ago

felixpleiva commented 1 year ago

Hi all,

Thank you very much for this fantastic package.

I have this model and I want to shape code by stock

fit1<-lmer(fresh_mass_delta ~ temperature cell_area_delta + oxygen cell_area_delta + sex + (1|stock),REML = FALSE, data=dat)

visreg(fit1,"cell_area_delta",by="temperature",cond=list(oxygen=10),overlay=TRUE, print.cond=TRUE,legend = FALSE, points=list(col=c("#2c7fb870", "#de2d2670"),pch=16,cex=1.4), line=list(col=c("#2c7fb8", "#de2d26"), lwd=4), xlab="Standardised cell area (%)", ylab="Standardised fresh mass (%)", ylim=c(-50,50),xlim=c(-50,50), xaxs = "i",yaxs = "i",#force origin of our x- and y-axes cex.axis=1.5,cex.lab=1.5) abline(h=0,lty=2,lwd=2) abline(v=0,lty=2,lwd=2)

Draw a polygon defining an area on the graph

xx = c(-49.8,-49.8,49.8,49.8) yy = c(35,49.8,49.8,35) polygon(xx,yy, col = 'grey90', border = NA) legend("bottomright", legend=c("17°C", "25°C"), lty = 1,lwd=4, bty="n", col=c("#2c7fb8", "#de2d26"),cex=1.4) text(0,42.5,"Hypoxia (10 kPa)",font=2,cex=1.5)

imagen

pbreheny commented 1 year ago

"I want to shape code by stock": I'm not sure what this means. You want the shape of the points to depend on stock? If so, just pass in a vector for pch, like so:

airquality$Heat <- cut(airquality$Temp, 3, labels=c("Cool","Mild","Hot"))
fit <- lm(Ozone ~ Solar.R + Wind + Heat, data=airquality)
v <- visreg(fit, "Wind", points.par=list(pch=as.numeric(model.frame(fit)$Heat), cex=1))

If you mean something else, please clarify.

pbreheny commented 1 year ago

Closing this issue since I never heard back from you.