1

I am having trouble finding a solution to plotting a large number of individual lines (columns) on one plot

Data has the following form:

Date       V1  V2  ... V100
1/1/05     21  34       45
2/1/05     23  45       65
3/1/05     43  46       73
....
25/1/05    56  12       81
etc

I am struggling with the best way to plot these 100 lines (V1-V100) on a single plot, seems that I am missing a simple solution.

Any assistance would be greatly appreciated.

Thank you

  • 1
    are you looking for a barplot for each of the columns v1 ... v100 in one single plot? – bim May 10 '16 at 11:23

1 Answers1

2

I get a little bit scared when you say you have 100 lines, might hurt your eyes doing this, so be careful!

The simplest I can come up with without manipulating the data is

matplot(df$Date, df, type="l"

With ggplot2, dplyr (for readability) and zoo packages you can do

df %>% select(matches("^V")) %>% zoo %>% autoplot

but you don't get the x-scale right there and I haven't spent time trying to get it right :).

With tidyr package you can also reshape the data before plotting.

df2 <- df %>% gather("variable","value", -Date)
ggplot(df2, aes(x=Date, y=value, color=variable)) + geom_line()

There are probably variations of this, or better ways :).

bytesinflight
  • 1,624
  • 2
  • 17
  • 28