I\'m looking for a log (base 10) colour scale to colour a SOM U-matrix plot in R. Specifically, looking for a colorRampPallette that will have more bins at the low end of the d
in ggplot
one can use scale_color_gradientn
. Here is an example with cars
data.
ggplot(cars)+
geom_point(aes(x = speed, y =dist, color = dist))+
scale_color_gradientn(colors = colorRampPalette(colors = c("blue", "white"))(nrow(cars)),
values = scales::rescale(log(sort(cars$dist))))
To summarize, one can define a linear gradient of any number of colors with colorRampPalette
function, and in scale_color_gradientn
you can map any of the colors to a certain value - the spread of the colors can be linear, log or arbitrary. Since values
argument accepts 0 - 1 range, scales::rescale
was used on the log transformed values.
to compare, here is without transformation
ggplot(cars)+
geom_point(aes(x = speed, y =dist, color = dist))+
scale_color_gradientn(colors = colorRampPalette(colors = c("blue", "white"))(nrow(cars)), values = scales::rescale(sort(cars$dist)))