Plot multiple colums from datatable

I want to plot all columns from a data table. My data table has 100 columns and 5 rows. Each row is a date and each column is a different person. How could I do it? I've tried the following code, but it only plots the last register:

plot1 <- ggplot(data, aes(x = date))
for (i in 1:100){
plot1 <- plot1 + geom_line(aes(y = data[ , i]))}

Could anyone help me? Thanks

Convert the data into long format first:
Pivot data from wide to long — pivot_longer • tidyr (tidyverse.org)

Then use aes(colour = colname) or aes(group = colname) within ggplot().

2 Likes

Thank you so much martin

Hi @ignareeva,
Did martin's answer solve your problem? If so, it would be great if you could mark their answer as the solution.

If you're still stuck, I'd be happy to help, especially if you can provide a minimal reproducible example of your data (some info on how to do that is here).

1 Like

Yes, Martin's a answer solved my problem. It was my first post in the blog and I didn't know how to mark it as solution. Thanks for your answer.

1 Like

Great, I'm glad to hear you got it sorted out! And no worries at all :slight_smile:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.