0

I am trying to plot a longer version of this:

enter image description here

From a file editor:

   Date, Price 
" 43,698 ", 113.000 
" 43,699 ", 112.875 
" 43,700 ", 113.125 
" 43,701 ", 113.375 
" 43,702 ", 113.625 
" 43,703 ", 113.875 
" 43,704 ",
" 43,705 ", 114.125 
" 43,706 ", 114.750 
" 43,707 ", 115.000 

My code is:

library(tidyverse) 
    southsea <- read_csv("C:/Users/Kevin/OneDrive/Documents/Open University/Research/south sea bubble/southseatest.csv")
    southsea <- filter(southsea,Price > 0)
    southsea$Date <-as.Date(southsea$Date, origin= "1899-12-30")
    ggplot(data= southsea, aes(x=Date,y=Price, group = 1 ))+
      geom_line()

The graph I'm getting of that short list above is [Note - this image is supposed to be just the 10 items above]:

enter image description here

The structure is showing the dates as chr - might that be the cause? In which case, how do I convert just that column to date (or number) format?

Thanks,

Kevin

Kevin A
  • 71
  • 7
  • 1
    It's hard to say more without knowing what your data look like, but [Lubridate](https://lubridate.tidyverse.org/) is pretty useful for dealing with conversions to and from dates. My guess is that excel's weird date system might be at work here, so perhaps [this](https://stackoverflow.com/questions/43230470/how-to-convert-excel-date-format-to-proper-date-in-r) may help. – akshaymoorthy Jul 08 '22 at 10:48
  • Thank you - but the link shows how to enter an individual item and convert it. How do I convert an entire csv column after read_csv? – Kevin A Jul 08 '22 at 11:13
  • Instead of an image please include a section from that csv-file or use `dput()` on (part of) your dataframe to share your data. Date axis aside, that chart looks valid, your 10 samples just cover the fraction of the first rising section. – margusl Jul 08 '22 at 11:18
  • Hi Margus - the image is taken from just the 10 lines- they are not the rising part ie the image is not of the entire data set, it's from a new file comprising just 10 lines. I'm happy to upload that csv file but cannot find instructions anywhere of how to do so – Kevin A Jul 08 '22 at 11:22
  • Just open the CSV-file in a text editor and include few lines from top of it to your question as a code block. – margusl Jul 08 '22 at 11:26
  • 1
    Does this answer your question? https://stackoverflow.com/questions/43230470/how-to-convert-excel-date-format-to-proper-date-in-r. I looks like your date column is a string, you will need to remove the comma and convert to a number, then follow the referenced solution. – Dave2e Jul 08 '22 at 11:39
  • I've converted the dates to numbers in the csv file (replaced in question) and added as.date() function as suggested. Before adding as.Date the plot worked . However now it shows x axis as numbers. Anyway to get them showing as dates? I had hoped the as.date function would achieve that. – Kevin A Jul 08 '22 at 12:36
  • Don't worry -solved it - now edited code in the question for others. Thanks everyone – Kevin A Jul 08 '22 at 12:48

0 Answers0