I have a dataframe that looks like this.
> head(df)
DGene JGene cdr3_len Sum
1 IGHD1 IGHJ1 0 22
2 IGHD1 IGHJ1 1 11
3 IGHD1 IGHJ1 2 16
4 IGHD1 IGHJ1 3 40
5 IGHD1 IGHJ1 4 18
6 IGHD1 IGHJ1 5 30
...
It is pretty simple to facet_grid.
ggplot(df,aes(x=cdr3_len,y=Sum)) + geom_line() + xlim(c(1,42)) + facet_grid(JGene~DGene,scales="free_y")
and getting something that looks like.
I was wondering if anyone could help me with adding a hline to the mean of each grid. Or possibly how to print the mean of each grid in the top right corner.
Thanks,
Edit - Full link to dataframe
Here's a way to add both text and a vertical line for the mean of
cdr3_len
by pre-computing the desired values (per @jwillis0720's comment):First, calculate the mean of
cdr3_len
for each panel and thenleft_join
that data frame to a second data frame that calculates the appropriate y-value for placing the text on each panel (because the appropriate y-value varies only by level ofJGene
).Now for the plot: