Search code examples
rdateformattimeline

R - How should I format a B.C.E. date in timevis?


I need to show a series of events in a timeline. Some of this events are before common era. I'm using timevis in R.

So far, I've tried the following code:

library("timevis")
d <- as.POSIXlt(as.Date("0001/01/01"))
d$year <- d$year -1
dates <- (as.Date(d))
names <- c("Test")

dt <- data.frame(start=dates,content=names)
print(dt)

timevis(dt, width = 900)

The above code shows an event in the beginning of the year 0 in timevis, which is wierd but is not a problem right now. the problem shows up as soon as I change to:

d$year <- d$year -2

The event jumps in the timeline to 01/01/2001

I just started yesterday with R for a personal research project, and I've never worked with BCE dates in any other language before. I've tried lubridate.

I've considered this question Date sequence in R spanning B.C.E. to A.D, but I'm asking if there's any timevis workaround, maybe. Because this timeline shows BCE years.

What's the proper way to format a BCE date?

I am looking forward to a bit of help - Thank you


Solution

  • There was a discussion on github recently about this topic. Using the information from there, you need the following to make it work on RStudio and in an app:

    • format the dates as strings
    • for BCE dates, you need a minus as prefix and in total 6 digits for the year: "-002000-01-01"
    • for CE dates, you need in total 4 digits for the year: "0010-01-01"

    Example code that works for me in RStudio:

    library(timevis)
    
    dt <- data.frame(content = c("test1", "test2", "test3", "test4"),
                     start = c("-000002-01-01", "-000001-01-01",
                                         "0010-01-01", "0100-01-01"))
    
    timevis(dt, width = 900)