rggplot2

Rich Factor bubble plot for RNA seq data


I am trying to make a bubble plot showcasing KEGG pathway information from an RNA seq experiment. I want the y axis to show pathway terms, the x to show rich factor, bubbles to be shaded based on p-vale and size of the bubble based on the gene number. I have attached images of what I want to make (Table 1- my input data) and example of how I want it (Figure 1- bubble plot example).Figure1Table 1


Solution

  • First of all - please, note that it is very bad form to share your dataset via an image, since an image is unable to be imported in any way to replicate your dataset. In this case, I had to type everything out as written into R via a data.frame() function. I would recommend for other questions, you share your dataframe via pasting the output of dput(your.df), or by using some example dataset like mtcars, iris, or diamonds to ask your question.

    With that being said, I'm going to try to replicate the image you show with ggplot2, assuming the columns in your dataset are df$pathway_terms, df$rf, df$pval, and df$gene as shown in your image.

    You want legends and adjustment of size= and color= aesthetics to be associated with your dataset, so I include those in the call. I'm using geom_point() as the main geom here and then it's a matter of adjusting the scale color (shown as rainbow in yours... so I used rainbow), and some themeing to match what you shared. Here it is:

    ggplot(df, aes(x=rf,y=pathway_term)) +
      geom_point(aes(color=pval,size=gene)) +
      scale_color_gradientn(colours = rainbow(5)) +
      labs(
        x='Rich Factor', y=NULL,
        color='P-value',size='Gene\nnumber'
      ) +
      theme(
        axis.title = element_text(face='bold'),
        axis.text = element_text(face='bold')
      )
    

    enter image description here