For each year, I have the number of an individual patient that belongs to one of three levels. I would like to calculate the relative frequency distribution of the three levels for each year. Say that 80% of patients are labeled with C and another patient with A and B. Since most have C, the distribution for A and B will not be visible. So, I changed the y axis. I had the following problem with ggplot: the color column for A and B is displayed, but for C it disappeared from the graph. Here I gave an example:
library(ggplot2) # Data set grp <- rep(c("A","B","C"), c(10,10,80)) year <- floor(runif(100)*10/3) df <- data.frame(grp,year) # Plot ggplot(df,aes(year)) + geom_histogram(aes(fill=grp),position="fill") + scale_y_continuous(lim=c(0,0.5))
If I delete the last line (scale_y ...), I get the whole range from 0 to 1 and all levels (colors) are displayed. With scale_y .. the level (color) of C disappears and only a gray background is visible. Does anyone know how I can avoid the color for C fading? Thanks for the tips.
source share