r - Comparative Histograms Separated by Factor -


have assignment need provide one-dimensional graphs eda sample code given answers of requirements (simple scatter , box plots , histogram) trying "spice up" little creating more interesting graphs. need couple.

the data set twin iq data across several studies/authors , wanting back-to-back histogram of twins separated author. far can overlay of authors or back of twins using ggplot stuck when trying separate in either 4 graphs or overlaid back-to-backs.

the code using overlay ggplot either geom_density or geom_histogram , code back-to-back came r-bloggers , used first snippet:

ggplot(df, aes(iq)) + geom_histogram(aes(x = x1, y = ..density..), fill = "blue") + geom_histogram( aes(x = x2, y = -..density..), fill = "green") 

what looking way combine these 2 techniques or how ggplot split graphs factor in same plot/lattice when do, example:

bwplot(y~x1.x2|author, data=df) 

the snippet using achieve separate plots includes facet_grid() such final code is:

ggplot(df, aes(y)) + facet_grid(~author) + geom_histogram(aes(x = x1, y = ..density..), fill = "green") + geom_histogram(aes(x = x2, y = -..density..), fill = "blue") 

i wasn't aware of facet_grid() function of ggplot thank mlavoie , brandon bertelsen.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -