0

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

O Ali
  • 13
  • 3
  • Please read and edit your question according to [How to make a great R reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – pogibas Jun 12 '20 at 07:27

1 Answers1

0

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

chemdork123
  • 12,369
  • 2
  • 16
  • 32
  • Firstly let me apologize to the community in which the question was asked. I am very grateful for for your code and precious time you spent in making the plot. I used the below code to make the plot as well but yours seems neater. library("ggplot2") S1<- ggplot(bubble, aes(x=RF, y=gene, size=GC, color=P)) + geom_point(alpha = 0.8) S1 S1 = S1+scale_color_gradient(low = "red2", high = "mediumblue", space = "Lab", limit = c(0.04, 0.03)) S1+scale_size(range = c(2, 8)) S1 – O Ali Jun 16 '20 at 06:10
  • One key point to understand on how R works is that the appearance of the plot also depends on the size and resolution of your **graphics device**. This means that if you resize your plot window, you get a different-looking plot because everything does not resize the same. If you are using `ggsave()` to create your image, this means that you can play around with the `width=` and `height=` to do the same. I think for this one I noticed it wasn't the right aspect ratio in my window, so played a bit with those arguments until the plot output in image looked like I wanted. Does that help? – chemdork123 Jun 16 '20 at 13:06
  • it helps it a great deal, thank you very much again for this help. :) – O Ali Jun 17 '20 at 21:38