问题
I have a ggplot stat_bin2d "heatmap".
library(ggplot2)
value<-rep(1:5, 1000)
df<-as.data.frame(value)
df$group<-rep(1:7, len=5000)
df<-df[sample(nrow(df), 3000), ]
ggplot(df, aes(factor(group), factor(value))) +stat_bin2d()
I have tried to add fill to aes:
aes(factor(group), factor(value),fill = (..count..)/mean(..count..))
as a way to mimic ..density.. (not accepted) does not seem to be accepted, but it is not what I am wanting - it seems to divide by the sum of the counts for the whole df. I want the count of values in each group (by x axis) normalised by the mean (or sum, or other stat) within the group. unfortunately, sum(..count..) seems to give the sum of the whole df, not only of the column.
来源:https://stackoverflow.com/questions/30803999/how-to-scale-normalise-values-of-ggplot2-stat-bin2d-within-each-column-by-x-a