Ggplot2 change color label

I want to build a matrix . To clearly see low values, the code is as follows.

p <- ggplot(data = melt(x))
p + geom_tile(aes(x=Var2,y=Var1,fill = value))

Now, to see the details, I prefer to use a square root scale. But if I change fill = valueto fill = the sqrt(value) range of the color gamut will also change (for example, the original c (0,100), now c (0,10)).

What I want is to build sqrt(value), but still use the color barvalue

I checked guide_colorbar(), but there is only an argument about whether to show labels, there are no arguments on how to set your own labels.

+4
source share
1 answer

Use the argument trans scale_fill_gradient:

p + 
    geom_tile(aes(x = Var2, y = Var1, fill = value)) + 
    scale_fill_gradient(trans = "sqrt")

Here is a sample graph using the following data:

x <- matrix(1:16, 4, 4)

enter image description here

, trans , , , .

+5

All Articles