gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 04:10:10 26 4
gpt4 key购买 nike

我正在尝试创建一个类似于在以下位置提问和回答的情节:( 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com