Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R ggplot stat_bin2d绘图中的渐变中断_R_Ggplot2 - Fatal编程技术网

R ggplot stat_bin2d绘图中的渐变中断

R ggplot stat_bin2d绘图中的渐变中断,r,ggplot2,R,Ggplot2,我在ggplot2包中使用stat\u bin2d创建了一个二维直方图。我想控制颜色渐变中的断点数量,以及这些断点的位置。我肯定我只是忽略了一些小的东西,但我不知道如何控制垃圾箱的破裂 例如: x <- rnorm(100)^2 y <- rnorm(100)^2 df <- data.frame(x,y) require(ggplot2) p <- ggplot(df, aes(x, y)) p <- p + stat_bin2d(bins = 20) p +

我在
ggplot2
包中使用
stat\u bin2d
创建了一个二维直方图。我想控制颜色渐变中的断点数量,以及这些断点的位置。我肯定我只是忽略了一些小的东西,但我不知道如何控制垃圾箱的破裂

例如:

x <- rnorm(100)^2
y <- rnorm(100)^2
df <- data.frame(x,y)
require(ggplot2)
p <- ggplot(df, aes(x, y)) 
p <- p + stat_bin2d(bins = 20)
p + scale_colour_gradient2(breaks=c(1,2,3,4,5,6))

xMe认为你可能想要较少被谈论的
scale\u color\u gradient2()
scale\u fill\u gradient2()

使用您的数据:

p + scale_fill_gradient2(breaks=c(1,2,3,4,5,6))
另请注意附加控制的可选参数
low
mid
high


下面是一个结合
cut
bin2d
的示例:

p <- ggplot(df, aes(x, y, fill=cut(..count.., c(0,6,8,9,Inf))))
p <- p + stat_bin2d(bins = 20)
p + scale_fill_hue("count")

p你的情节让我想扮演阿塔里。看看传说中的颜色与情节中使用的颜色不匹配。@Gavin-hmm,好主意。看起来整个范围的值都被绘制出来了,只有在指定的地方才会显示打断…有点奇怪。我想知道这是否是我们想要的行动?无论如何,添加
limits=c(1,6)
似乎可以为图例提供更直观的值,以匹配实际绘制的内容。可能还有其他选择,所以这并不意味着详尽。@Gavin@Chase-Setting
limits=c(1,6)
使图例颜色与绘图相匹配(至少对我来说是这样),但我承认我没有解释。打断就像轴记号一样。改变它们只会改变图例,它不会以任何方式修改比例。而且我怀疑你是否真的想要gradient2给出没有自然中点的结论。我没有比这更好的答案了。这正是我要找的。谢谢我喜欢这个解决方案,但我想知道是否有办法在(0、6、8、9、Inf)断点处标记刻度,而不是用范围来表示刻度。