I'm using ggplot to create a facet wrap of histograms + density curves. This is the dataframe I'm plotting (~300 rows):
head(merged)
# tpl strand base score ipdRatio motif
# 1 24501 0 A 51 3.108 AAGTACTCG
# 2 58809 0 A 69 4.095 GAGTACTAC
# 3 65614 0 A 61 3.341 TAGTACTCA
# 4 78494 0 A 92 4.968 GAGTACTAC
# 5 92127 0 A 23 1.702 AAGTACTTA
# 6 193102 0 A 96 5.255 GAGTACTCG
Here's a link to the csv file so that you can read the dataframe in yourselves: dropbox link
If I try this, with nothing but binwidth specified in geom_histogram:
# Graph Histogram
ggplot(merged, aes(score)) +
geom_histogram(binwidth=25) +
geom_density() +
facet_wrap(~ motif,ncol=7) +
labs(title=paste("MOTIF:",motif_f),x="Methylation Score",y="Frequency")
However if I try to create density plots for each individual plot by adding aes(y=..density..)
into geom_histogram like so:
# Graph Histogram
ggplot(merged, aes(score)) +
geom_histogram(aes(y=..density..),binwidth=25) +
geom_density() +
facet_wrap(~ motif,ncol=7) +
labs(title=paste("MOTIF:",motif_f),x="Methylation Score",y="Frequency")
I get an undesired result where the y parameters are stretched out for some plots and cramped for others:
Any suggestions on how to overlay density plots on these plots while keeping the same y parameters as they are in the first image?