plotPresGrid: plotPresGrid

View source: R/plotPresGrid.R

plotPresGridR Documentation

plotPresGrid

Description

Creates a grid plot of the presence or density of detections across time where the x-axis is the hour of the day and the y-axis is the date

Usage

plotPresGrid(
  x,
  start = NULL,
  end = NULL,
  bin = c("hour", "minute", "30min", "15min"),
  type = c("presence", "density"),
  by = NULL,
  alpha = 0.5,
  gps = NULL,
  format = c("%m/%d/%Y %H:%M:%S", "%m-%d-%Y %H:%M:%S",
    "%Y/%m/%d %H:%M:%S", "%Y-%m-%d %H:%M:%S"),
  fill = "blue",
  color = NA,
  cmap = viridis_pal()(25),
  title = TRUE,
  plotTz = "UTC"
)

Arguments

x

a data.frame of detections, must have a column UTC that contains the time of detection as a POSIXct object in UTC timezone

start

the beginning datetime of the plot, if NULL will be set to the minimum time in x

end

the ending datetime of the plot, if NULL will be set to the maximum time in x

bin

the unit of time for each rectangle in the grid, must be one of "hour", "minute", "30min", or "15min"

type

one of either "presence" or "density". If "density", then boxes will be colored according to the number of detections in each timeBin will be plotted. If "presence", then each box will be colored by fill

by

(optional) if not NULL, specifies the name of a column in x to split and color the rectangles by. Only valid for presence plots.

alpha

opacity of rectangles, only used if by is not NULL

gps

(optional) if not NULL, a data.frame of GPS coordinates covering the date range of x. These are used to calculate sunrise and sunset information which is shown as a shaded dark region in the background of the plot. The data.frame must have columns "UTC", "Latitude", and "Longitude". If columns "Latitude" and "Longitude" are present in x, then these values will be used and you do not need to provide separate GPS data here

format

date format if UTC column of x is a character

fill

the fill color for the boxes, only used if type is "presence"

color

the outline color for the boxes, only used if type is "presence"

cmap

the colormap to use for the boxes, only used if type is "density"

title

if TRUE, a title will automatically created. If any other value, that will be used for the title of the plot.

plotTz

the timezone to use for plotting the data. Note that inputs must still be in UTC, this option allows you to create plots scaled to local time. Valid values come from OlsonNames

Value

a ggplot2 object

Author(s)

Taiki Sakai taiki.sakai@noaa.gov

Examples


df <- data.frame(UTC = as.POSIXct(runif(1e2, min=0, max=7*24*3600),
                                  origin='1970-01-01 00:00:00', tz='UTC'),
                 label = sample(letters[1:3], 1e2, replace=TRUE))
plotPresGrid(df, type='presence', bin='hour')
plotPresGrid(df, type='density', bin='hour')
plotPresGrid(df, type='density', bin='30min')
gps <- data.frame(UTC = as.POSIXct('1970-01-01 00:00:00', tz='UTC'),
                 Latitude=32.4,
                 Longitude = -118)
plotPresGrid(df, gps=gps, bin='hour')
# coloring presence grid by label column
plotPresGrid(df, gps=gps, by='label')
# can be confusing if there is a lot of overlap, ggplot output can be split
library(ggplot2)
plotPresGrid(df, gps=gps, by='label') + facet_wrap(vars(label), ncol=2)
# using "by" with type="density" defaults to this facet_wrap behavior
# since color is already being used to represent density
plotPresGrid(df, gps=gps, by='label', type='density')
# can adjust facet_wrap parameters by adding it again
plotPresGrid(df, gps=gps, by='label', type='density') + facet_wrap(vars(label), ncol=2)


PAMmisc documentation built on June 22, 2024, 9:37 a.m.