Here's an example of a binned density plot:
library(ggplot2)
n <- 1e5
df <- data.frame(x = rexp(n), y = rexp(n))
p <- ggplot(df, aes(x = x, y = y)) + stat_binhex()
print(p)
It would be nice to adjust the color scale so that the breaks are log-spaced, but a try
my_breaks <- round_any(exp(seq(log(10), log(5000), length = 5)), 10)
p + scale_fill_hue(breaks = as.factor(my_breaks), labels = as.character(my_breaks))
Results in an Error: Continuous variable () supplied to discrete scale_hue.
It seems breaks is expecting a factor (maybe?) and designed with categorical variables in mind?
There's a not built-in work-around I'll post as an answer, but I think I might just be lost in my use of scale_fill_hue
, and I'd like to know if there's anything obvious I'm missing.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…