This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Genes time-series plots

Dear Biostars

I wonder if someone could give me some tips on how to build a graph similar to this in R:

enter image description here

My data has this format, different days, divided by severity and the genes (normalised z-score)

I tried ggplo2 + geom_line but no progress, nothing worked.

enter image description here

Best, Leite

time-series genes r plots proteins

1 answer

You'll want to use the pivot_longer function so you have a column for day, a column for severity, a column for gene, and a column of values. Then in ggplot, your aes will be x = day, y = values, color = severity. You might also want to use facet_wrap(~ gene).

Dear Trivas,

I try like you said, but it didn't work...

   Oxphos_proteins <- Oxphos_proteinas %>% pivot_longer(cols=c("COX6C", "COX7A2",   "COX7C"),
                names_to='Genes',
                values_to='z_score')

ggplot(Oxphos_proteins, aes(x = day, y = z_score)) +
  geom_line(aes(color = severity), size = 1, na.rm=TRUE)

enter image description here

It's because your day vector is not of type numeric.

Thanks Trivas!

I tried some changes, but it still doesn't look good. Any other tips?

enter image description here

Log in to answer this question.