title: R: How to draw a plot with day of the week in x-axis using ts_seasonal() and ts_heatmap() function
body: <p>I'm learning about using &quot;ts&quot; object and do visualization in R. For the practice, I want to plot a seasonality line plot and heatmap, just like the plots show below.
  <a href="https://i.stack.imgur.com/DmGLF.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DmGLF.jpg" alt="enter image description here" /></a>
  <a href="https://i.stack.imgur.com/3JinQ.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3JinQ.jpg" alt="enter image description here" /></a></p>
  <p>My data is transaction records of buildings in Taipei during year 2020. For each transaction record, date was recorded. Here is the data after cleaning: <strong><a href="https://drive.google.com/file/d/1_Cn8AUTZ1Yo3cbTLpxLnDiB4j5dov5Ts/view?usp=sharing" rel="nofollow noreferrer">I'm data</a></strong></p>
  <p>For seasonality line plot, x-axis should be day of the week, y-axis should be transection counts, and each line represent a quarter of year 2020.</p>
  <p>For heatmap, x-axis should be also day of the week, y-axis should be quarter and colors represent counts.</p>
  <p>I have tried several methods and this is the one most close to the example (the code is showed below). Although the plots looks quite similar, I think the data was interpreted by R in the wrong way.</p>
  <pre><code># Setting Environment
  library(ggplot2)
  library(tidyverse)
  library(readxl)
  library(xts)
  library(TSstudio)
  
  # Load Data
  taipei_trans = read.csv(&quot;taipei_trans_clean.csv&quot;)
  
  # Data Processing
    ## Change data into wide table
  taipei_trans_w = xtabs(~ Date, data = taipei_trans) %&gt;% as.data.frame()
  
    ## Turn data into date form
  taipei_trans_w$Date = taipei_trans_w$Date %&gt;% as.character() %&gt;% 
    as.numeric() %&gt;% + 19110000 %&gt;% as.character() %&gt;% 
    as.Date(format = &quot;%Y%m%d&quot;)
  
    ## Filter data by date
  taipei_trans_w = subset(taipei_trans_w, Date &gt;= &quot;2020-01-01&quot;)
  taipei_trans_w = subset(taipei_trans_w, Date &lt;= &quot;2020-12-31&quot;)
  
    ## Build a ts object
  qutrs = taipei_trans_w$Date %&gt;% quarters() %&gt;% 
    factor(levels = c(&quot;Q1&quot;, &quot;Q2&quot;, &quot;Q3&quot;, &quot;Q4&quot;))
  
  wdays = weekdays(taipei_trans_w$Date) %&gt;%
    factor(levels = c(&quot;星期一&quot;, &quot;星期二&quot;, &quot;星期三&quot;, &quot;星期四&quot;, &quot;星期五&quot;, &quot;星期六&quot;, &quot;星期日&quot;),
           labels = c(&quot;Monday&quot;, &quot;Tuesday&quot;, &quot;Wednesday&quot;, &quot;Thursday&quot;, &quot;Friday&quot;, &quot;Saturday&quot;, &quot;Sunday&quot;))
  
  trans_wq = data.frame(Count = taipei_trans_w$Freq, Weekday = wdays, Quarter = qutrs) %&gt;%
    group_by(Weekday, Quarter) %&gt;%
    summarise(Count = sum(Count)) %&gt;% 
    arrange(Quarter)
  
  trans_ts = ts(trans_wq[,3], start = 1, frequency = 7)
  
  # Plotting
  ts_seasonal(trans_ts)
  ts_heatmap(trans_ts)
  </code></pre>
  <p>and these are my results:</p>
  <p><a href="https://i.stack.imgur.com/PbW7H.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PbW7H.jpg" alt="enter image description here" /></a>
  <a href="https://i.stack.imgur.com/T8kgA.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/T8kgA.jpg" alt="enter image description here" /></a></p>
  <p>I'm very thankful if there is anyone can tell me what is the key point or is there any other method!</p>