我想用六角形联调绘制X和Y的“散点图”。目前,我有这样的代码:
library(ggplot2)
X=rnorm(1000)
Y=rnorm(1000)
Z=sin(X)
df = data.frame(X,Y,Z)
p = ggplot(df, aes(X, Y)) +
stat_binhex()
plot(p)代码生成一个图形,其中每个六边形的颜色表示垃圾箱中的点数。我希望颜色在我的df中反映Z变量(因为这些点是二进制的,颜色反映了binned Z的平均值)。我该怎么做?
发布于 2017-04-06 04:27:27
我认为您需要stat_summary_hex,可以用scale_fill_continuous指定颜色
ggplot(df, aes(X, Y)) +
stat_summary_hex(aes(z = Z)) +
scale_fill_continuous(low = 'blue', high = 'red')https://stackoverflow.com/questions/43245349
复制相似问题