spiralDate {berryFunctions}R Documentation

Spiral graph of time series

Description

Plot seasonality of (daily) time series along spiral

Usage

spiralDate(
  dates,
  values,
  data,
  drange = NA,
  vrange = NA,
  months = substr(month.abb, 1, 1),
  add = FALSE,
  shift = 0,
  prop = NA,
  zlab = substitute(values),
  format = "%Y",
  nint = 1,
  ...
)

Arguments

dates

Dates in ascending order. Can be character strings or strptime results, as accepted (and coerced) by as.Date

values

Values to be mapped in color with colPoints along seasonal spiral

data

Optional: data.frame with the column names as given by dates and values

drange

Optional date range (analogous to xlim), can be a vector like dates. DEFAULT: NA

vrange

Optional value range (analogous to ylim), can be a vector like values. DEFAULT: NA

months

Labels for the months. DEFAULT: J,F,M,A,M,J,J,A,S,O,N,D

add

Add to existing plot? DEFAULT: FALSE

shift

Number of days to move January 1st clockwise. DEFAULT: 0

prop

Proportion of the data to be actually plotted, used in spiralDateAnim. DEFAULT: NA (ignored)

zlab

Title of colPointsLegend

format

Format of date labels see details in strptime. DEFAULT: "%Y"

nint

Number of interpolation segments between points, only used if lines=TRUE (passed to colPoints). DEFAULT: 1 (with long time series, the colPoints default of 30 is too high!)

...

Further arguments passed to colPoints, but not Range (use vrange)

Value

invisible data.frame with date, vals, and the plotting coordinates

Author(s)

Berry Boessenkool, berry-b@gmx.de, May 2016

See Also

seasonality, colPoints, as.Date

Examples

# synthetic seasonal Data
set.seed(42)
fakeData <- data.frame(time = as.Date("1985-01-01")+0:5000,
                       vals = cumsum(rnorm(5001))+50          )
fakeData$vals <- fakeData$vals + sin(0:5000/366*2*pi)*max(abs(fakeData$vals))

sp <- spiralDate(time,vals, data=fakeData)
tail(sp)
spiralDate(time,vals, data=fakeData, drange=as.Date(c("1980-01-01", "2004-11-15")), lines=TRUE)

par(mfrow=c(1,3), mar=c(3,3,6,1), mgp=c(2,0.6,0), las=1)
colPoints(time,vals,vals, data=fakeData, col=divPal(100), add=FALSE, legend=FALSE,
          lines=TRUE, pch=NA, nint=1, lwd=2)
title(main="classical time series\nworks badly for long time series\nshows trends well")

seasonality(time, vals, fakeData, col=divPal(100), mar=c(3,3,6,1), legend=FALSE, main="", shift=61)
title(main="yearly time series\nday of year over time\nfails for cyclicity over all year")

spiralDate(time,vals, data=fakeData, col=divPal(100), legargs=list(y1=0.7,y2=0.8))
title(main="spiral graph\nshows cyclic values nicely
            trends are harder to detect\nrecent values = more visual weight")

par(mfrow=c(1,1))

# Data with missing values:
fakeData[1300:1500, 2] <- NA
spiralDate(time,vals, data=fakeData, lines=TRUE) # no problem
# Missing data:
fakeData <- na.omit(fakeData)
spiralDate(time,vals, data=fakeData, lines=TRUE) # problematic for lines
spiralDate(time,vals, data=fakeData, pch=3)      # but not for points

## Real data:
#library2("waterData")
#data(exampleWaterData)
#spiralDate(dates, val, data=q05054000LT, lines=TRUE, lwd=3)


[Package berryFunctions version 1.20.1 Index]