add_rasterly.Rd
Add trace to a Plotly visualization.
add_rasterly_heatmap( p, x = NULL, y = NULL, z = NULL, ..., data = NULL, inherit = TRUE, on = NULL, size = NULL, scaling = NULL ) add_rasterly_image( p, x = NULL, y = NULL, z = NULL, ..., data = NULL, inherit = TRUE, color = NULL, on = NULL, size = NULL )
p | A |
---|---|
x | Numeric vector or expression. The x variable, to be passed on to |
y | Numeric or expression. The y variable, to be passed on to |
z | Numeric. A numeric matrix (optional), to be processed with |
... | Arguments (i.e., attributes) passed along to the trace type or |
data | A data.frame or SharedData object (optional). |
inherit | Logical. Inherit attributes from plotly? |
on | Numeric vector or expression. Provides the data on which to reduce, to be passed on to |
size | Numeric vector or expression. Pixel size for each observation, to be passed on to |
scaling | Character string or function. The scaling method to be used for the trace. |
color | Numeric vector or expression. Pixel color for each observation, to be passed on to |
if (FALSE) { if(requireNamespace("plotly") && requireNamespace("data.table") && requireNamespace("lubridate")) { # Load data url1 <- "https://raw.githubusercontent.com/plotly/datasets/master/uber-rides-data1.csv" ridesRaw_1 <- url1 %>% data.table::fread(stringsAsFactors = FALSE) url2 <- "https://raw.githubusercontent.com/plotly/datasets/master/uber-rides-data2.csv" ridesRaw_2 <- url2 %>% data.table::fread(stringsAsFactors = FALSE) url3 <- "https://raw.githubusercontent.com/plotly/datasets/master/uber-rides-data3.csv" ridesRaw_3 <- url3 %>% data.table::fread(stringsAsFactors = FALSE) ridesDf <- list(ridesRaw_1, ridesRaw_2, ridesRaw_3) %>% data.table::rbindlist() time <- lubridate::ymd_hms(ridesDf$`Date/Time`) ridesDf <- ridesDf[, 'Date/Time':=NULL][, list(Lat, Lon, hour = lubridate::hour(time), month = lubridate::month(time), day = lubridate::day(time))] ############################# add_rasterly_heatmap ############################# #### quick start p <- plot_ly(data = ridesDf) %>% add_rasterly_heatmap(x = ~Lat, y = ~Lon) p #### set artificial scaling function zeroOneTransform <- function(z) { minz <- min(z) maxz <- max(z) M <- matrix((z - minz)/(maxz - minz), nrow = dim(z)[1]) return(M) } plot_ly(data = ridesDf) %>% add_rasterly_heatmap(x = ~Lat, y = ~Lon, on = ~-Lat, reduction_func = "max", scaling = zeroOneTransform) %>% plotly::layout( xaxis = list( title = "x" ), yaxis = list( title = "y" ) ) ############################# add_rasterly_image ############################# p <- plot_ly(data = ridesDf) %>% add_rasterly_image(x = ~Lat, y = ~Lon, color = ~hour, # even `color_map` is deprecated, # it is still a good way to specify the color mapping color_map = hourColors_map, plot_width = 400, plot_height = 400) p } }