I’m making a ggplot2 graph in which I’ve mapped an extremely wide range of numbers to the color. The problem is that my numbers are log-normally distributed, so I have a bunch of numbers all getting set to the same color since the gradient in ggplot2 assumes that the values are on a pretty similar linear scale. Here are some example data:
DF <- data.frame(A = 1:10,
B = 1:10,
C = 10^seq(-5, 4))
When I use the regular ggplot2 settings, all but my very last point are dark blue.
ggplot(DF, aes(x = A, y = B, color = C)) +
geom_point()
If I log transform these values, the colors look better, but now my legend shows log-transformed values rather than the actual values.
ggplot(DF, aes(x = A, y = B, color = log10(C))) +
geom_point()
I also tried using scale_color_gradientn in hopes that maybe I could set the numerical breaks the way I wanted, but that really did not work. The extremely small values are now all grey or missing.
ggplot(DF, aes(x = A, y = B, color = C)) +
geom_point() +
scale_color_gradientn(colors = grDevices::blues9,
values = 10^seq(-5, 4))
Is there a way to make the colors of my gradient be on a log10 scale but the labels still be the actual values?