Question

A great way to visualise the results of a regression in R is the visreg package. I particularly like the plots that show an interaction with different shades of two colours:

library(visreg)
fit.heat <- lm(Ozone ~ Solar.R + Wind + Temp, data = airquality)
visreg2d(fit.heat, "Wind", "Temp", plot.type = "image")

(from the visreg documentation)

The two colours used are red and blue.

Question

How can I change the colors? Shades of red and blue don't look too well in black and white print, red and blue can't be distinguished. I would be happy with a scale from blue to white for example. Any chances this can be done?

Was it helpful?

Solution

You can change the color of the graph by adding a colour argument inside visreg2d function. You can for example use one of the standard R palettes such as terrain.colors() or heat.colors()or modify/create your own palettes e.g. with the package RColorBrewer (as in the example attached).

visreg2d(model, x="RELATEDNESS", y = "Hs_obs", scale = "response", 
xlab = "Relatedness", ylab = "Heterozygosity", main = "Flower abundance", 
zlim = c(0,100), col = colorRampPalette(brewer.pal(9,"Reds"))(20))

enter image description here

OTHER TIPS

If you type in

edit(visreg2d)

you will be able to view the color pallet for this function. You can edit here and choose a color combination of your choice.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top