I have a dataframe, df
,similar to the following:
Time Sample_A Sample_B Sample_C
0 0.12 0.14 0.15
1 0.13 0.20 0.21
2 0.31 0.34 0.36
I am reading in this data from a text file, in which the number of columns will always be changing. I would like to use ggplot in order to quickly and easily graph the x value (always Time) by all of the y values (Sample A, B, C, ....) onto a single graph. The names of the Y-variables are always changing as well.
In essence, I'd like to avoid doing the following on repeat:
ggplot(df, aes(x = Time, y = Sample_A) + geom_line()
ggplot(df, aes(x = Time, y = Sample_B) + geom_line()
I have tried to create a vector that contains all names of the columns and apply that as the Y-values to the aes
function, however it returns the number of variables, rather than the values within the variables.
What is the most efficient way to go about this?