plotRasterly: plotRasterly

Description Usage Arguments Value See Also Examples

View source: R/plotRasterly.R

Description

Display large data set in plotly

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
plotRasterly(
  data = NULL,
  mapping = aes(),
  ...,
  plot_width = 400,
  plot_height = 400,
  x_range = NULL,
  y_range = NULL,
  background = "white",
  color = NULL,
  show_raster = TRUE,
  drop_data = FALSE,
  variable_check = FALSE,
  alpha = 0.5,
  shape = 19,
  point_size = 0.5,
  as_image = FALSE,
  sizing = c("stretch", "fill", "contain")
)

Arguments

data

Dataset to use for generating the plot. If not provided, data must be supplied in each layer of the plot. For best performance, particularly when processing large datasets, use of data.table is recommended.

mapping

Default list of aesthetic mappings to use for plot. The same with ggplot2 aes. See details.

...

Other arguments which will be passed through to layers.

plot_width

Integer. The width of the image to plot; must be a positive integer. A higher value indicates a higher resolution.

plot_height

Integer. The height of the image to plot; must be a positive integer. A higher value indicates a higher resolution.

x_range

Vector of type numeric. The range of x; it can be used to clip the image. For larger datasets, providing x_range may result in improved performance.

y_range

Vector of type numeric. The range of y; it can be used to clip the image. For larger datasets, providing y_range may result in improved performance.

background

Character. The background color of the image to plot.

color

Vector of type character. It will determine this color vector is a color_map or color_key automatically.

  • color_map: It has Color(s) used to draw each pixel. The color_map is extended by linear interpolation independently for RGB. The darkness of the mapped color depends upon the values of the aggregation matrix.

  • color_key: Vector of type character. The color_key is used for categorical variables; it is passed when the color aesthetic is provided.

show_raster

Logical. Should the raster be displayed?

drop_data

Logical. When working with large datasets, drops the original data once processed according to the provided aes() parameters, using the remove() function. See details for additional information.

variable_check

Logical. If TRUE, drops unused columns to save memory; may result in reduced performance.

alpha

The transparency of points, from 0 to 1.

shape

The shape of points, see pch.

point_size

The size of points.

as_image

Logical value. If FALSE, image raster will be transformed into a data frame, hence a points layer would be pipped on plotly; conversely, a raster layer will be added.

sizing

It affects only with as_image = TRUE. Specifies which dimension of the image to constrain. One of "stretch" "fill", "contain". see https://plot.ly/r/reference/#Layout_and_layout_style_objects

Value

a plotly widget

See Also

ggRasterly, plot.rasterly

Examples

 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
## Not run: 
 library(rasterly)
 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))]
 # A point layer is added
 plotRasterly(data = ridesDf, 
              mapping = aes(x = Lat, y = Lon, color = hour),
              color = hourColors_map,
              as_image = FALSE)
  # An image layer is added       
  plotRasterly(data = ridesDf, 
               mapping = aes(x = Lat, y = Lon, color = hour),
               color = hourColors_map,
               as_image = TRUE)
  
 }

## End(Not run)

rasterly documentation built on July 2, 2020, 2:12 a.m.