0

So I am a bit of an R novice, I am trying to plot a graph that has multiple line each colour coded. My data is currently in the format of 3 columns (Name,Total, Year) and 270 rows. There is 15 years for each name and the data looks something similar to this:

Name  Year  Total
X      1      4
Y      1      6
Z      1      3

I want each name to have its own line running from the first year in the data to the last with the totals being plotted. I am however unaware how to separate out each of these names to ensure that they are plotted separately. My data is currently in a tab delimited text file from excel. I was wondering how to proceed from here. Any help is appreciated

gawi
  • 2,843
  • 4
  • 29
  • 44
  • 1
    if you use `dput(head(df))` to share the head of your data frame here and the plot you are using (the code for it) I can help you reshape the data to get what you want – sconfluentus Apr 10 '20 at 22:46
  • Does this answer your question? [Plotting two variables as lines using ggplot2 on the same graph](https://stackoverflow.com/questions/3777174/plotting-two-variables-as-lines-using-ggplot2-on-the-same-graph) – tjebo Apr 11 '20 at 09:35
  • structure(c("function (x, df1, df2, ncp, log = FALSE) ", "{", " if (missing(ncp)) ", " .Call(C_df, x, df1, df2, log)", " else .Call(C_dnf, x, df1, df2, ncp, log)", "}"), .Dim = c(6L, 1L), .Dimnames = list(c("1", "2", "3", "4", "5", "6"), ""), class = "noquote") – Jake Holness Apr 11 '20 at 16:00

1 Answers1

1

With tidyverse it should look like this:

library(tidyverse)

df %>%
ggplot(aes(x = Year, y = Total, color = Name)) +
geom_line()
eastclintw00d
  • 2,250
  • 1
  • 9
  • 18