Search code examples
rtimeline

Creating a timeline based on years in R


I am fairly new to coding with R. I am working with relatively easy data just a large amount of it. I am trying to create a timeline based on the years these species of whale were sighted. So I just have two variables (year and species) and 151 observations. There are a total of 25 species to plot on this time line and I have provided a small example of my data below.

year       species
1792    Megaptera novaeangliae
1792    Physeter macrocephalus
1793    Physeter macrocephalus
1832    Physeter macrocephalus
1833    Physeter macrocephalus

I have tried creating the timeline using timelineS and timelineG as well as vistime. TimelineG gets close to creating what I want but it does not seem to plot anything. The code is as follows:

timelineG(t8, start="year", end="year", names="species")

timelineG results

I am just kind of stuck. I do have the month and day that the species were sighted so I can add that back if needed. Thank you in advance for any guidance.


Solution

  • or like this using ,

    dta <- data.frame(species = c('Megaptera novaeangliae','Physeter macrocephalus',
                                  'Physeter macrocephalus','Physeter macrocephalus',
                                  'Physeter macrocephalus'),
                      year = c(1792,1792,1793,1832,1833))
    
    #str(dta)
    dta$year <- as.Date(ISOdate(dta$year, 1, 1)) # assuming beginning of year for year 
    # str(dta)
    
    
    timelineS(dta, main = "BGoodwin's species example")
    

    enter image description here