parvin karimi parvin karimi - 2 years ago 54
R Question

How to change the default blue-color in `densCols` in R?

as part of the
in R base by default gives a blue color determined by
. I was wondering if there might be a way we could change
to any different color while maintaining the

Notice, I need a single color.

As an example, how can we change the blue-color in the plot given by the following R code:

x = rnorm(1e4, 2, 1) ; y = rnorm(1e4, 1, 2)
plot(x, y, col = densCols(x, y, colramp = colorRampPalette(blues9[-(1:3)])) )

Answer Source

See ?colorRampPalette. You can pass any vector of colour names or values to the function. The default blues9[-(1:3)] just passes the last 6 elements of the 9-element vector of colour values, blues9.

For example, using the Greens palette from RColorBrewer:

plot(x, y, col = densCols(x, y, colramp = colorRampPalette(brewer.pal(6, "Greens"))))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download