Skip to content

Color customization in the plot.visreg2d function #110

Answered by pbreheny
AlexisZr asked this question in Q&A
Discussion options

You must be logged in to vote

You're almost there, just apply cut() to z:

library(visreg)
fit <- lm(Ozone ~ Solar.R + Wind + Temp + I(Wind^2) + I(Temp^2) +
            I(Wind*Temp)+I(Wind*Temp^2) + I(Temp*Wind^2) + I(Temp^2*Wind^2),
          data=airquality)
v <- visreg2d(fit, x="Wind", y="Temp", plot=FALSE)
n_colors <- 99  
color_palette <- colorRampPalette(c("blue","red"))(n_colors)
zcol <- cut(v$z, n_colors)
plot(v, plot.type="rgl", col=color_palette[zcol])

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@AlexisZr
Comment options

Answer selected by pbreheny
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #109 on June 09, 2023 16:04.