This is a useful function for visualising your data and how the number of records change over time. This is key for understanding biases that may be present in your data (Isaac et al, 2014).
Usage
recsOverTime(
time_period,
Log = FALSE,
col = "black",
xlab = "Year",
ylab = ifelse(Log, "log(Frequency)", "Frequency"),
...
)
Arguments
- time_period
A numeric vector of user defined time periods, or a date vector, as long as the number of observations.
- Log
Logical, should the y-axis be on a log scale?
- col
Passed to barplot, the colour of bars
- xlab
Passed to barplot, the x-axis label
- ylab
Passed to barplot, the y-axis label
- ...
other arguements to pass to barplot
Examples
if (FALSE) {
# Create data
n <- 3000 #size of dataset
nyr <- 10 # number of years in data
nSamples <- 30 # set number of dates
nSites <- 15 # set number of sites
# Create somes dates
first <- as.POSIXct(strptime("2010/01/01", "%Y/%m/%d"))
last <- as.POSIXct(strptime(paste(2010+(nyr-1),"/12/31", sep=''), "%Y/%m/%d"))
dt <- last-first
rDates <- first + (runif(nSamples)*dt)
# taxa are set as random letters
taxa <- sample(letters, size = n, TRUE)
# three sites are visited randomly
site <- sample(paste('A', 1:nSites, sep=''), size = n, TRUE)
# the date of visit is selected at random from those created earlier
time_period <- sample(rDates, size = n, TRUE)
# combine this to a dataframe (adding a final row of 'bad' data)
df <- data.frame(taxa = c(taxa,'bad'),
site = c(site,'A1'),
time_period = c(time_period, as.POSIXct(strptime("1200/01/01", "%Y/%m/%d"))))
# This reveals the 'bad data'
recsOverTime(df$time_period)
# remove and replot
df <- df[format(df$time_period, '%Y') > 2000, ]
recsOverTime(df$time_period)
# plot with style
recsOverTime(df$time_period, col = 'blue', main = 'Records of Species A',
ylab = 'log(number of records)', Log = TRUE)
}