
Last chance! 50% off unlimited learning
Sale ends in
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
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"
)
a ggplot2 object
a data.frame of detections, must have a column UTC
that contains the
time of detection as a POSIXct object in UTC timezone
the beginning datetime of the plot, if NULL
will be set to the minimum
time in x
the ending datetime of the plot, if NULL
will be set to the maximum
time in x
the unit of time for each rectangle in the grid, must be one of "hour", "minute", "30min", or "15min"
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
(optional) if not NULL
, specifies the name of a column in x
to split and
color the rectangles by. Only valid for presence plots.
opacity of rectangles, only used if by
is not NULL
(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
date format if UTC
column of x
is a character
the fill color for the boxes, only used if type
is "presence"
the outline color for the boxes, only used if type
is "presence"
the colormap to use for the boxes, only used if type
is "density"
if TRUE
, a title will automatically created. If any other value, that will be
used for the title of the plot.
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
Taiki Sakai taiki.sakai@noaa.gov
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)
Run the code above in your browser using DataLab