title: How do I convert a column from "unknown" to date in R to use ggplot scale_x_date?
body: <p>I have a column in my dataframe which shows as &quot;unknown&quot; when I hover the cursor over the column title. It shows as a date as printed below with <code>head(dataframe)</code></p>
  <p>Example data:</p>
  <pre><code>date&lt;date&gt;  courses&lt;int&gt;  tasks&lt;int&gt;
  1   2020-01-02  14      199
  2   2020-01-03  14      246
  3   2020-01-06  14      227
  4   2020-01-07  14      83
  5   2020-01-08  14      116
  6   2020-01-09  14      178
  </code></pre>
  <p>I have tried:</p>
  <ol>
  <li>Formatting the column as &quot;date&quot; in excel before importing</li>
  <li>Changing the import settings to &quot;date&quot; when loading both CSV and XLS files</li>
  <li>Importing the data as &quot;character&quot; and them changing to numeric and then date. This does provide the correct format but the same &quot;unknown&quot; heading.</li>
  </ol>
  <p>I was able to add a week column, so it seems like the data is behaving as a date in some instances but not others.</p>
  <pre><code>DFweek &lt;- dataframe %&gt;% mutate(Week = week(date))
  head(DFweek)
  
  date&lt;date&gt;  courses&lt;int&gt;  tasks&lt;int&gt;  &lt;week&gt;&lt;dbl&gt;
  1   2020-01-02  14      199 1
  2   2020-01-03  14      246 1
  3   2020-01-06  14      227 1
  4   2020-01-07  14      83  1
  5   2020-01-08  14      116 2
  6   2020-01-09  14      178 2
  </code></pre>
  <p>The column always shows as a date type</p>
  <pre><code>&gt; class(dataframe$date)
  [1] &quot;Date&quot;
  
  &gt; str(dataframe$date)
   Date[1:290], format: &quot;2020-01-02&quot; &quot;2020-01-03&quot; &quot;2020-01-06&quot; &quot;2020-01-07&quot; &quot;2020-01-08&quot; &quot;2020-01-09&quot; &quot;2020-01-10&quot; &quot;2020-01-13&quot; &quot;2020-01-14&quot;
  </code></pre>
  <p>This code successfully makes a plot</p>
  <pre><code>b &lt;- diff(ylim.prim)/diff(ylim.sec)
  a &lt;- ylim.prim[1] - b*ylim.sec[1]
  
  dataframeplot &lt;- ggplot(dataframe, aes(date, courses)) +
    geom_line() +
    geom_bar(aes(y = a + tasks*b), color = &quot;red&quot;, stat='identity') +
    scale_y_continuous(&quot;Open Courses&quot;, sec.axis = sec_axis(~ (. - a)/b, name = &quot;Tasks Completed&quot;)) +
    scale_x_continuous(&quot;Month&quot;, breaks = 1:12) +
    ggtitle(&quot;Title&quot;) +
    theme(axis.line.y.right = element_line(color = &quot;red&quot;), 
          axis.ticks.y.right = element_line(color = &quot;red&quot;),
          axis.text.y.right = element_text(color = &quot;red&quot;), 
          axis.title.y.right = element_text(color = &quot;red&quot;)
          
          ) 
  dataframeplot
  </code></pre>
  <p>I would like to use scale_x_date, but the below code gives me an error</p>
  <pre><code>&gt; dataframeplot2&lt;- ggplot(dataframe, aes(date, courses)) +
  +   geom_line() +
  +   geom_bar(aes(y = a + tasks*b), color = &quot;red&quot;, stat='identity') +
  +   scale_y_continuous(&quot;Open Courses&quot;, sec.axis = sec_axis(~ (. - a)/b, name = &quot;Tasks Completed&quot;)) +
  +   scale_x_date(&quot;Month&quot;, breaks = 1:12) +
  +   ggtitle(&quot;Title&quot;) +
  +   theme(axis.line.y.right = element_line(color = &quot;red&quot;), 
  +         axis.ticks.y.right = element_line(color = &quot;red&quot;),
  +         axis.text.y.right = element_text(color = &quot;red&quot;), 
  +         axis.title.y.right = element_text(color = &quot;red&quot;)
  +         
  +         ) 
  &gt; dataframeplot2
  Error: Invalid input: date_trans works with objects of class Date only
  </code></pre>
  <p>Does this mean that my date column isn't actually in date format?</p>