1

I have some expression data and I am interested in making some individual plots per gene. To make this plot:

plot

I used this code:

ggplot(geneOfInterestmelt, aes(x=variable, y=value, fill=fill, colour = fill)) + 
  geom_dotplot(binaxis='y', stackdir='center', dotsize=0.5)+
  scale_fill_manual(values = c("seagreen3", "steelblue"))+
  scale_colour_manual(values = c("seagreen3", "steelblue"))+
  xlab("")+
  ylab("Counts per million (CPM)")+
  theme(axis.title.y = element_text(face = "bold"),
        legend.text = element_text(face = "bold"),
        axis.text.x = element_text(face = "bold", colour ="black"),
        axis.text.y = element_text(face = "bold", colour ="black"),
        axis.title.x = element_text(face = "bold", colour = "black"),
        legend.title = element_text(face = "bold"),
        panel.grid.major = element_line(size = 0.25, linetype = 'dashed',
                                        colour = "grey"),
        panel.grid.minor = element_line(size = 0.25, linetype = 'dashed',
                                        colour = "grey"),
        panel.background = element_blank(),
        axis.line = element_line(colour = "black"),
        plot.title = element_text(face = "bold", size = 10, hjust = 0.5))+
  theme(legend.position = "none")+
  stat_summary(fun.y = mean, fun.ymin = mean, fun.ymax = mean,
               geom = "crossbar", width = 0.15, colour=c("seagreen3","steelblue"))

What i want to add in the corner is all stored in a data frame so i can add code to call it, I basically want the geneId, with the logFC underneath, and the adjusted p value under that. All of this in the top right hand corner. Like say, this is all contained within a dataframe that accompanies the data, with the idea that this code can be used to make these reproducible graphs just by switching out the gene name.

I seen some people use annotate() to add this, but unless im not mistaken (which i could be cus im new), annotate needs to be mapped. And since each gene has different expression levels the mapping cant therefore be the same in each gene.

Is this possible?

Thanks in advance!

lordjord93
  • 47
  • 1
  • 7
  • Please provide a reproducible example of your dataset by following this link: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – dc37 Apr 21 '20 at 20:56
  • 2
    `+ geom_label(data=newdata, aes(x=-Inf, y=-Inf, label=lbl))` will place it in the top-left corner of the plot. From there, look for inset or use `hjust` or `vjust` to align it the way you want. – r2evans Apr 21 '20 at 20:56
  • https://stackoverflow.com/questions/38439211/figure-labels-add-text-on-graphs-in-the-same-location-despite-figure-size – rg255 Apr 21 '20 at 20:57
  • @r2evans I have used that code but I just ended up with a tiny blue box in the bottom left corner. Im sorry im really new to R, would you be able to elaborate? – lordjord93 Apr 22 '20 at 17:59
  • If you see a too-small box without the text that you have assigned within the `aes`thetic, then that likely means you need to adjust `position=`, `hjust=`, and/or `vjust=`. If you haven't already, take a look at [`?geom_text`](https://ggplot2.tidyverse.org/reference/geom_text.html) (same for `geom_label`) to see what they do and how to use them. – r2evans Apr 22 '20 at 18:06

0 Answers0