To adjust the scale ticks and breaks to percentiles in a continuous colorbar using scale_fill_gradientn
in ggplot2, you can use the limits
and the breaks
arguments.
The limits
argument sets the minimum and maximum values of the scale. By default, it uses the minimum and maximum values of the data. You can set it to the percentiles that you want to use, for example:
limits = c(5, 95)
The breaks
argument sets the positions of the ticks in the scale. By default, it uses a sequence of numbers between the minimum and maximum values of the data. You can set it to percentiles as well, using the quantile
function, for example:
breaks = seq(0, 1, by = 0.1) # or breaks = quantile(data, probs = seq(0, 1, by = 0.1))
You can combine both arguments in the scale_fill_gradientn
function, like this:
ggplot(data, aes(x, y, fill = z)) + geom_point() + scale_fill_gradientn(colors = c("blue", "white", "red"), limits = c(5, 95), breaks = seq(0, 1, by = 0.1))
This will create a continuous colorbar with ticks and breaks at the 5th, 15th, 25th, ..., and 95th percentiles of the data.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-06-04 12:25:47 +0000
Seen: 17 times
Last updated: Jun 04 '23
How can one ensure that sub-classes have uniform method parameters in TypeScript?
How can the calculation of matrix determinant be performed using CUDA?
How can code repetition be prevented when using (box)plot functions?
When I attempt to generate a database, why does the azure-cosmos-emulator become unresponsive?
What steps can I take to prevent my webpage from slowing down when all parts of a div are displayed?