ggplot2中的对数色标会挤压某些图例编号 [英] Logarithmic color scale in ggplot2 squishes certain legend numbers
问题描述
I am trying to create a plot similar to what was asked and answered at: (Is there a built-in way to do a logarithmic color scale in ggplot2?).
在上面的链接中结合问题和接受的答案中的代码,创建以下MWE:
Combining the code from the question and accepted answer at the above link creates the following MWE:
require(ggplot2)
n <- 1e5
df <- data.frame(x = rexp(n), y = rexp(n))
p <- ggplot(df, aes(x = x, y = y)) + stat_binhex()
my_breaks = c(2, 10, 50, 100, 200, 6000)
p + scale_fill_gradient(name = "count", trans = "log", breaks = my_breaks, labels = my_breaks)
这将导致以下图像:
由于某些原因,图例的缩放比例看起来与上述链接中接受的答案的输出不同.在我创建的绘图中,图例将某些数字挤压在一起(例如50、100、200),而链接上发布的绘图似乎均匀地分配了图例数字.下图显示在左侧帖子中创建的图例,在右侧显示我的图例.
For some reason, the scaling of the legend looks different than the output from the accepted answer at the above-posted link. In the plot I created, the legend squishes certain numbers together (eg. 50, 100, 200), whereas the plot posted on the link seems to evenly distribute the legend numbers. The image below shows the legend created in the post on the left, and my legend on the right.
我喜欢链接中情节的传说美感,并希望重新创建它.有什么想法可能会改变我的想法吗?谢谢.
I like the aesthetics of the legend from the plot from the link, and want to recreate it. Any ideas what I may be doing differently? Thank you.
推荐答案
使用guide="legend"
p + scale_fill_gradient(name = "count", trans = "log",
breaks = my_breaks, labels = my_breaks, guide="legend")
签出?scale_fill_gradient
这篇关于ggplot2中的对数色标会挤压某些图例编号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!