r - ggplot2 中的对数色标压缩了某些图例数字

标签 r ggplot2 legend

我正在尝试创建一个类似于在以下位置提问和回答的情节:( Is there a built-in way to do a logarithmic color scale in ggplot2?)。

将上述链接中的问题代码和已接受的答案结合起来,创建以下 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)  

这导致了下图:

My output

出于某种原因,图例的缩放比例看起来与上面发布的链接中接受的答案的输出不同。在我创建的图中,图例将某些数字压缩在一起(例如 50、100、200),而链接上发布的图似乎均匀分布了图例数字。下图左侧是帖子中创建的图例,右侧是我的图例。

Legend comparison

从链接的情节来看,我喜欢传说中的美学,并想重新创作它。有什么想法我可能会做不同的事情吗?谢谢。

最佳答案

使用guide="legend"

p + scale_fill_gradient(name = "count", trans = "log",
                        breaks = my_breaks, labels = my_breaks, guide="legend")

查看 ?scale_fill_gradient

enter image description here

关于r - ggplot2 中的对数色标压缩了某些图例数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44855061/

相关文章:

r - 生成列 ID

r - CDF超出R ggplot2中的值范围

r - 在ggplot2图例中组合线型和颜色

python - 小方 block 而不是传说中的线条?

r - 很难将图例添加到我的图表中

r - data.table 的 frollmean() 和 forecast 的 ma() 之间的细微差别,顺序相同

r - 如何更改点并向云图添加回归(使用 R)?

r - 将 data.table 中的列表分配/提取值到列

r - nearPoints 无法从 Shiny 的坐标信息中自动推断出 `xvar`

r - 如何为以下数据制作条形图?