r - Normalizing faceted histograms separately in ggplot2 -


my questions similar normalizing y-axis in histograms in r ggplot proportion i'd add bit.

in general, have 6 histograms in 2x3 facet design, , i'd normalize each of them separately. i'll try make sample data set here give idea:

hvalues=c(3,1,3,2,2,5,1,1,12,1,4,3) season=c("fall","fall","fall","fall","winter","winter","winter","winter","summer","summer","summer","summer") year=c("year 1","year 1","year 2","year 2","year 1","year 1","year 2","year 2","year 1","year 1","year 2","year 2") group=c("fall year 1","fall year 1","fall year 2","fall year 2","winter year 1","winter year 1","winter year 2","winter year 2","summer year 1","summer year 1","summer year 2","summer year 2") all=data.frame(hvalues,season,year) 

using

ggplot(all, aes(x=hvalues,group=group)) +  geom_histogram(aes(y=..count../sum(..count..))) +  facet_grid(season ~ year) 

gives proportions overall (i.e. combining facets). i'd each group facet normalized 1. hvalues not integers in actual data - numerical.

i novice using r, , appreciate help. in advance!

the solution is:

ggplot(all, aes(x=hvalues)) +     facet_grid(season ~ year,drop=t) +     geom_histogram(aes(y=(..count..)/tapply(..count..,..panel..,sum)[..panel..])) 

i stole question

i feel question might duplicate of 1 way.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

javascript - Clean way to programmatically use CSS transitions from JS? -

android - send complex objects as post php java -