Change the colormap of a contour plot in R

632 views Asked by At

I am trying to change the default colormap of a contour plot, but I can't figure out how.

This is the code I am using:

library(rsm)

A <- c(-1,+1,-1,+1,-1,+1,-1,+1)
B <- c(-1,-1,+1,+1,-1,-1,+1,+1)
y <- c(26,34,21,29,27,33,20,30)

model <-lm(y ~ A+B)
summary(model)

contour(model, ~A+B, image = TRUE)

The contour plot generates the image below. I would like to change the color map to a color-blind friendly one, as viridis.

Thanks in advance for any help.

enter image description here

1

There are 1 answers

0
Marco Sandri On BEST ANSWER

You can specify a new color palette in rsm::contour.lm using the img.col argument:

library(viridis)
contour(model, ~A+B, image = TRUE, img.col=viridis(50))

enter image description here