library(ggplot2)
data = diamonds[, c(\'carat\', \'color\')]
data = data[data$color %in% c(\'D\', \'E\'), ]
I would like to compare the histogram of
You can scale them by group by using the ..group.. special variable to subset the ..count.. vector. It is pretty ugly because of all the dots, but here it goes
ggplot(data, aes(carat, fill=color)) +
geom_histogram(aes(y=c(..count..[..group..==1]/sum(..count..[..group..==1]),
..count..[..group..==2]/sum(..count..[..group..==2]))*100),
position='dodge', binwidth=0.5) +
ylab("Percentage") + xlab("Carat")
