I want to make a barplot with binned data on the x axis and a corresponding probability on the y axis.
Each bin should contain 100 observations.
Here's a snapshot of my working data frame:
head(covs)
y Intercept slope temp heatload cti
1 0 1 1.175494e-38 -7.106242 76 100
2 0 1 4.935794e-01 -7.100835 139 11
3 1 1 3.021236e-01 -7.097794 126 12
4 1 1 1.175494e-38 -7.097927 75 98
5 0 1 1.175494e-38 -7.098462 76 98
6 0 1 1.175494e-38 -6.363284 76 100
And initial execution:
slopes <- as.matrix(covs$slope)
binned.slopes=cut2(slopes, m=100)
heights <- tapply(covs$y,binned.slopes,mean)
barplot(heights, ylim=c(0,1),
ylab="Probability of permafrost",
xlab="Slope",
col="lightgrey")
With the following result:
I have two questions:
What would be a better way to represent the x-axis without sacrificing explanatory power? The problem is that the intervals are all different lengths, given that bins are determined by observation count.
Is there a better way to do this in ggplot2?