missatomicbomb
missatomicbomb

Reputation: 31

How to plot multiple rows into single graph

I am trying to figure this out but I am having trouble.

I am trying to plot this data but I"m not sure how to even begin. I read other posts about using ggplot2 put then I am not sure if I have to write a different column for every FundID. Also I am curious how I format my data to "long format" for ggplot2.

#I have tried this `plot(filename,type = "o",col = "red", xlab = "Time", ylab = "Amount", main = "Amount over time")

#But I get this error which I don't understand Error in plot.default(...) : formal argument "type" matched by multiple actual arguments

My goal is to plot my data as a time series line graph and have each FundID have its own color. Something like this post. The 1-8 at the top are the periods and I want to create a graph with the periods 1-8 on the x-axis and the numbers on a scale from 0-100 on the y-axis. I have attached my data for reference. Thank you in advance!

Data

Upvotes: 0

Views: 201

Answers (1)

Ben Norris
Ben Norris

Reputation: 5747

You need to pivot your data to long form. You can do that with the tidyr package.

library(tidyr)
library(ggplot2)
data %>%
  pivot_longer(-FundID, names_to = "x", values_to = "y") %>%
  ggplot(aes(x, y, color = FundID)) + 
  geom_line()

Upvotes: 0

Related Questions