title: Convert a dataframe whose row name is month and column name is year to a time series object using R
body: <p>Say I have an excel file with format like this (to download from <a href="https://www.dropbox.com/scl/fi/t5wbo2g11q3xhgq2ftvwr/dataset1.xlsx?dl=0&amp;rlkey=za7brp0bnicgnysc2q2yhgxeb" rel="nofollow noreferrer">this link</a>):</p>
  <p><a href="https://i.stack.imgur.com/dwLCO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dwLCO.png" alt="enter image description here" /></a></p>
  <p>Note the first column is year and the first row is month.</p>
  <p>I try to convert it to time series object then draw a seasonal plot using <code>ggseasonplot</code> or <code>ggplot2</code>.</p>
  <pre><code>df &lt;- openxlsx::read.xlsx('dataset1.xlsx', sheet='Sheet1', colNames=TRUE, rowNames = TRUE)
  # df &lt;- t(df)
  df &lt;- ts(df, start = c(2008, 1), end=c(2021, 12), frequency = 12)
  forecast::ggseasonplot(df, col=rainbow(12), year.labels=TRUE)
  </code></pre>
  <p>Output:</p>
  <pre><code>Error in data.frame(y = as.numeric(x), year = trunc(round(time(x), 8)),  : 
    arguments imply differing number of rows: 2352, 168
  </code></pre>
  <p>How could I do that correctly using R? Thanks in advance.</p>
  <p><strong>References:</strong></p>
  <p><a href="https://pkg.robjhyndman.com/forecast/reference/seasonplot.html" rel="nofollow noreferrer">https://pkg.robjhyndman.com/forecast/reference/seasonplot.html</a></p>
  <p><a href="https://afit-r.github.io/ts_exploration" rel="nofollow noreferrer">https://afit-r.github.io/ts_exploration</a></p>