基于成功率填充的 stat_bin2d

bee*_*vee 5 plot r histogram ggplot2

我有一个包含以下数据的表:

> head(sweet)
  interval  urgency success
1     3138      761       1
2     3210     2189       1
3     3243     1256       1
4     8776      823       1
5     3094     1405       1
6     3137     1062       1
Run Code Online (Sandbox Code Playgroud)

成功取值为 0 和 1。我正在寻找不同紧迫性值的成功率,因此我绘制了这样的直方图:

ggplot(sweet, aes(x=urgency, fill=success==0)) + geom_histogram(position='fill')
Run Code Online (Sandbox Code Playgroud)

情节1

现在我想看看紧急和间隔组合的成功率,但类似的方法无济于事:

ggplot(sweet, aes(x=urgency, y=interval, fill=success==0)) + geom_bin2d()
Run Code Online (Sandbox Code Playgroud)

情节2

有没有办法让填充连续显示成功/失败的比率,而不是在 2d bin plot 上显示无用的二进制值?

koh*_*ske 5

您可以使用stat_summary2d

ggplot(sweet, aes(interval, urgency, z = success)) + stat_summary2d()
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明