0

I'm new in R, I have to plot a data.frame containing 50 time series, the columns names are the names of each series and the rows names are the references dates; for each series I have 373 observations. The data.frame is called data

I tried with plot(data) but i get the error Error in plot.new() : figure margins too large

so I tried with ggplot(data) this time i'm not getting errors, but it returns a blank white figure: enter image description here

I'm trying to have a graph with the dates (so the row names) on the x-axixs, and each column of the data.frame (so each time series), as a different line with the level on the y axixs.

Thanks in advance!

Community
  • 1
  • 1
Lapo
  • 17
  • 3
  • Seems like this should answer your question: [How to plot row names on x axis...](https://stackoverflow.com/questions/45310757/how-to-plot-row-names-on-x-axis-with-x-and-y-columns-on-y-axis) – chemdork123 May 17 '20 at 15:29
  • Does this answer your question? [How to plot Row.names on x axis with x and y columns on y axis?](https://stackoverflow.com/questions/45310757/how-to-plot-row-names-on-x-axis-with-x-and-y-columns-on-y-axis) – chemdork123 May 17 '20 at 15:29
  • The ggcharts package just added a function to do just as you described - plot a time series df where each column is a series: https://twitter.com/thomas_neitmann/status/1261604059850715137?s=21 – bs93 May 17 '20 at 19:42

1 Answers1

0

Your ggplot call is blank because you didn't specify a geometric object. Also for ggplot to work efficiently, your data should be in the "long" format. Assuming you have loaded the core tidyverse and that your 50 time series are columns 2 through 51,

data2 <- data %>%
  pivot_longer( 2:51, names_to="series_name", values_to="series_value" )

Now assuming that your first column is named Date, you can get the plot you want as follows

data2 %>%
  ggplot( aes(x=Date) ) +
  geom_line( aes(y=series_value, group=series_type) )
statstew
  • 301
  • 1
  • 6