Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

stat_bin2d with fill based on success rate

I have a table with following data:

> 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

Success takes values of 0 and 1. I'm looking for a success rate for different values of urgency, so I draw a histogram like this:

ggplot(sweet, aes(x=urgency, fill=success==0)) + geom_histogram(position='fill')

plot1

Now I want to look at success rate for combination of urgency and interval, but similar approach does not help:

ggplot(sweet, aes(x=urgency, y=interval, fill=success==0)) + geom_bin2d()

plot2

Is there a way to make fill continuously show ratio of success/failure instead of useless binary value on a 2d bin plot?

like image 275
beevee Avatar asked Sep 28 '12 13:09

beevee


1 Answers

You can use stat_summary2d:

ggplot(sweet, aes(interval, urgency, z = success)) + stat_summary2d()

enter image description here

like image 118
kohske Avatar answered Oct 20 '22 04:10

kohske