To generate "pretty breaks" related to quantiles of your data when using `scale_fill_fermenter` in `ggplot2`, you need to adjust the way you define the breaks and the values for the scale.
Here's a step-by-step approach to doing this:
1. **Calculate Quantiles**: Determine the quantiles of your data. You can use the `quantile()` function in R.
2. **Create Breaks**: Use these quantiles to create breaks for your scale.
3. **Use `scale_fill_fermenter`**: Apply those breaks to the `scale_fill_fermenter` function.
Here's an example:
```r
library(ggplot2)
library(scales) # for percent_format()
# Example data
set.seed(42)
dat <- data.frame(x = rnorm(100), y = rnorm(100), z = rnorm(100))
# Calculate quantiles
quantiles <- quantile(dat$z, probs = seq(0, 1, length.out = 7)) # Adjust length.out for more/less breaks
# Create ggplot with scale_fill_fermenter
ggplot(dat, aes(x = x, y = y, fill = z)) +
geom_tile() +
scale_fill_fermenter(
type = "div", # or "seq" or "qual", depending on your data
breaks = quantiles,
labels = percent_format(accuracy = 1), # Optional: for prettier labels
na.value = "grey50"
) +
theme_minimal()
```
In this example, `length.out` defines the number of breaks you want. You can adjust this depending on how many quantiles you desire. The `scale_fill_fermenter` function will then map these quantile breaks onto the color scale you define. This approach should give you visually "pretty" breaks that correspond to the distribution of your data.