This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to make line graph with circles in R

Hello,

I saw these figures in a paper and wanted to make a similar graphs. Is there a function to do this kind of line graph in R that you would recommend?

I have a list of genes and would need to run go term enrichment on them, then obtain some p-values so that they can be represented as circle size on the graph.

Your input is appreciated, thank you.

Graphs

r

Speaking generically since you didn't provide example data, you would minimally start off with a 3 column data frame df with columns fold_change, pval, and what I assume is day.

Your call to ggplot would then look something like.

ggplot(df, aes(x=day, y=fold_change)) +
  geom_line() +
  geom_point(aes(size=-log10(pval)))

Adding additional lines and such would require dataset specific modifications to the input data or ggplot call, but I won't cover those since example data and desired output wasn't provided.

1 answer

Sure, you can just call both geom_point() and geom_line(). If you want to make them look exactly like the authors, I'd probably pass group into the main aes() call and "size = -log10(p-value)" into the aes() call just for geom_point()

Edit: I agree with rpolicastro, but I just realized you should also add color to the main aes() also. Copying his example, now with a fourth column called tissue:

ggplot(data, aes(x=day, y=fold_change, color = tissue)) +
  geom_line() +
  geom_point(aes(size=-log10(pval)))

Log in to answer this question.