0

If I have a dataset like this

Series Name X1 X2 ... X99 X100
A 23 35 ... 53 13
B 17 25 ... 43 34

How do I plot in R so that the X-axis is X1,X2...,X99,X100 and I have a linplot for each series name (A-E)

Attempting to plot this results in a scatterplot matrix.

I am looking for a line plot where the x axis is my headers in R. I will attach my code as well as the plot in python that I am looking for.

I know that I could make a new Variable X and have something like

Series Name X Value
A 1 23
B 1 17
A 2 35
B 2 25
... ... ...
A 99 53
B 99 43
A 100 13
B 100 34

But I was wondering if there was a way to tell R to plot the headers. If there is no way and it has to be done like the second table is there some example R code that will make the process of changing the table easy?

I will include my data and an example plot of what I want.

Plot of X1-100

Pastebin of data https://pastebin.com/Fg6hDdjh

#Says I have to include code when using pastebin
  • 1
    library(tidyverse); your_data %>% pivot_longer(-"Series Name") %>% mutate(x = parse_number(name) %>% ggplot(aes(x, value, color = "Series Name") – Jon Spring Mar 14 '21 at 23:29
  • Pivot longer is definitely what I am looking for but I couldn't seem to get your code to run, left everything the same apart from changing 'your_data' to 'df' (the name of my data). It just runs forever and when I cancel it I get 'Error : unexpected symbol in : – Hariboharry Mar 14 '21 at 23:42
  • Best practice on this site is to include in the question (and not as a link) an example of your data (or at least something with the same structure) and code you've tried. The easiest and most useful way to do this is to include the output of `dput(head(your_data))`. That way we can exactly replicate your issue on our computers. – Jon Spring Mar 14 '21 at 23:48
  • I researched pivot_longer and found the solution using "cols = starts_with("X"). Thanks for recommending that function! The majority of my coding experience is in python but wanted to learn some R also. – Hariboharry Mar 14 '21 at 23:51

1 Answers1

0

Using pivot_longer and cols = starts_with("X") solved this.