Description Usage Arguments Examples
Add trace to a Plotly visualization.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
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 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | ## Not run:
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
}
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.