Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201894

How to convert column values into dates for plotting ggplot in R

$
0
0

I would like to convert my column that has specific dates for each month. Ex: I converted my col that has abbreviations for each month to match the specific date data is collected. Reference below:

updated_df_2018$End_Date <- ifelse(updated_df_2018$Month=="Oct", "10/24/2017",
                                   ifelse(updated_df_2018$Month=="Nov", "11/28/2017",
                                          ifelse(updated_df_2018$Month=="Dec", "12/26/2017",
                                                 ifelse(updated_df_2018$Month=="Jan", "1/23/2018",
                                                        ifelse(updated_df_2018$Month=="Feb", "2/20/2018",
                                                               ifelse(updated_df_2018$Month=="Mar", "3/27/2018",
                                                                      ifelse(updated_df_2018$Month=="Apr", "4/24/2018",
                                                                             ifelse(updated_df_2018$Month=="May", "5/29/2018",
                                                                                    ifelse(updated_df_2018$Month=="Jun", "6/26/2018",
                                                                                           ifelse(updated_df_2018$Month=="Jul", "7/24/2018",
                                                                                                  ifelse(updated_df_2018$Month=="Aug", "8/28/2018",
                                                                                                         ifelse(updated_df_2018$Month=="Sep", "9/25/2018",
                                                                                                                NA  )))))))))))) # all other values map to NA

As you can see, for each month there is now a new column that has the raw date (month/day/year). However, when i plot - and put this col as my x axis - each month is sperate instead of a continuous plot.. When I use as.Date(col, "%d/m/y%") it converts but moves the date to 2020 and changes the order.

Any help would useful - would like to plot the change in overall sales for each building across the two year span (2017/18 to 2018/19).

Thanks!!


Viewing all articles
Browse latest Browse all 201894

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>