├── _pkgdown.yml ├── .gitattributes ├── .Rproj.user ├── shared │ └── notebooks │ │ └── patch-chunk-names └── 84277BCC │ └── cpp-complilation-config ├── docs ├── _config.yml ├── logo.png ├── reference │ ├── rplot-1.png │ ├── rplot-2.png │ ├── rplot-3.png │ ├── static-1.png │ ├── static-2.png │ ├── static-3.png │ ├── static-4.png │ ├── figures │ │ ├── logo.png │ │ ├── add_rasterizer.gif │ │ ├── grid_rasterizer.png │ │ └── plotly_rasterizer.gif │ ├── image2data-1.png │ ├── reexports.html │ ├── is.rasterly.html │ ├── color_map.html │ └── is.rasterlyBuild.html ├── pkgdown.yml ├── articles │ ├── images │ │ └── introduction │ │ │ ├── anyAgg.png │ │ │ ├── darkBg.png │ │ │ ├── ggUber.png │ │ │ ├── meanAgg.png │ │ │ ├── image2data.png │ │ │ ├── uberBasic.png │ │ │ ├── uberColor.png │ │ │ ├── add_rasterizer.gif │ │ │ └── uberColorCover.png │ └── index.html ├── link.svg ├── docsearch.js ├── pkgdown.js ├── pkgdown.css ├── LICENSE-text.html ├── 404.html └── authors.html ├── LICENSE ├── src-x64 ├── aggCpp.o ├── RcppExports.o ├── rasterly.dll └── aggregationCpp.o ├── src-i386 ├── aggCpp.o ├── rasterly.dll ├── RcppExports.o └── aggregationCpp.o ├── man ├── figures │ ├── logo.png │ ├── add_rasterizer.gif │ ├── grid_rasterizer.png │ └── plotly_rasterizer.gif ├── is.rasterly.Rd ├── is.rasterlyBuild.Rd ├── reexports.Rd ├── color_map.Rd ├── rasterly_build.Rd ├── grapes-set-grapes.Rd ├── rasterly_guides.Rd ├── image2data.Rd ├── rasterly-package.Rd ├── extract.Rd ├── rasterize_points.Rd ├── rplot.Rd ├── add_rasterly.Rd ├── rasterly.Rd ├── ggRasterly.Rd ├── plotRasterly.Rd ├── rasterly_points.Rd └── static.Rd ├── tests ├── testthat.R └── testthat │ └── Rplots.pdf ├── pkgdown └── favicon │ ├── favicon.ico │ ├── favicon-16x16.png │ ├── favicon-32x32.png │ ├── apple-touch-icon.png │ ├── apple-touch-icon-60x60.png │ ├── apple-touch-icon-76x76.png │ ├── apple-touch-icon-120x120.png │ ├── apple-touch-icon-152x152.png │ └── apple-touch-icon-180x180.png ├── R ├── rasterly-package.R ├── reexports.R ├── color_setting.R ├── is_rasterly.R ├── unreported_functions.R ├── get_aggregation_sd.R ├── get_aggregation_var.R ├── get_aggregation_m2.R ├── rasterize_points.R ├── merge_operator.R ├── rasterly_guides.R ├── get_aggregation_any.R ├── get_aggregation_max.R ├── get_aggregation_min.R ├── extract.R ├── get_aggregation_last.R ├── get_aggregation_first.R ├── get_aggregation_sum.R ├── image2data.R ├── add_rasterly_image.R ├── utils.R ├── RcppExports.R ├── get_aesthetics.R ├── rplot.R ├── get_arguments.R ├── as_raster.R ├── plotRasterly.R ├── rasterly.R └── add_rasterly_heatmap.R ├── .gitignore ├── vignettes ├── images │ └── introduction │ │ ├── anyAgg.png │ │ ├── darkBg.png │ │ ├── ggUber.png │ │ ├── meanAgg.png │ │ ├── uberBasic.png │ │ ├── uberColor.png │ │ ├── image2data.png │ │ ├── add_rasterizer.gif │ │ └── uberColorCover.png └── introduction.html.asis ├── .Rbuildignore ├── codecov.yml ├── rasterly.Rproj ├── .travis.yml ├── DESCRIPTION ├── NAMESPACE └── README.md /_pkgdown.yml: -------------------------------------------------------------------------------- 1 | destination: docs 2 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | src/* linguist-vendored 2 | -------------------------------------------------------------------------------- /.Rproj.user/shared/notebooks/patch-chunk-names: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-architect -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | YEAR: 2019 2 | COPYRIGHT HOLDER: Plotly, Inc. 3 | -------------------------------------------------------------------------------- /docs/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plotly/rasterly/HEAD/docs/logo.png -------------------------------------------------------------------------------- /src-x64/aggCpp.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plotly/rasterly/HEAD/src-x64/aggCpp.o -------------------------------------------------------------------------------- /src-i386/aggCpp.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plotly/rasterly/HEAD/src-i386/aggCpp.o -------------------------------------------------------------------------------- /man/figures/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plotly/rasterly/HEAD/man/figures/logo.png -------------------------------------------------------------------------------- /src-i386/rasterly.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plotly/rasterly/HEAD/src-i386/rasterly.dll -------------------------------------------------------------------------------- /src-x64/RcppExports.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plotly/rasterly/HEAD/src-x64/RcppExports.o -------------------------------------------------------------------------------- /src-x64/rasterly.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plotly/rasterly/HEAD/src-x64/rasterly.dll -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(rasterly) 3 | 4 | test_check("rasterly") 5 | -------------------------------------------------------------------------------- /src-i386/RcppExports.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plotly/rasterly/HEAD/src-i386/RcppExports.o -------------------------------------------------------------------------------- /docs/reference/rplot-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plotly/rasterly/HEAD/docs/reference/rplot-1.png -------------------------------------------------------------------------------- /docs/reference/rplot-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plotly/rasterly/HEAD/docs/reference/rplot-2.png -------------------------------------------------------------------------------- /docs/reference/rplot-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plotly/rasterly/HEAD/docs/reference/rplot-3.png -------------------------------------------------------------------------------- /src-i386/aggregationCpp.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plotly/rasterly/HEAD/src-i386/aggregationCpp.o -------------------------------------------------------------------------------- /src-x64/aggregationCpp.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plotly/rasterly/HEAD/src-x64/aggregationCpp.o -------------------------------------------------------------------------------- /tests/testthat/Rplots.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plotly/rasterly/HEAD/tests/testthat/Rplots.pdf -------------------------------------------------------------------------------- /docs/reference/static-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plotly/rasterly/HEAD/docs/reference/static-1.png -------------------------------------------------------------------------------- /docs/reference/static-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plotly/rasterly/HEAD/docs/reference/static-2.png -------------------------------------------------------------------------------- /docs/reference/static-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plotly/rasterly/HEAD/docs/reference/static-3.png -------------------------------------------------------------------------------- /docs/reference/static-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plotly/rasterly/HEAD/docs/reference/static-4.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plotly/rasterly/HEAD/pkgdown/favicon/favicon.ico -------------------------------------------------------------------------------- /R/rasterly-package.R: -------------------------------------------------------------------------------- 1 | #' @keywords internal 2 | #' @aliases rasterly-package 3 | "_PACKAGE" 4 | 5 | NULL 6 | 7 | -------------------------------------------------------------------------------- /docs/reference/figures/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plotly/rasterly/HEAD/docs/reference/figures/logo.png -------------------------------------------------------------------------------- /docs/reference/image2data-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plotly/rasterly/HEAD/docs/reference/image2data-1.png -------------------------------------------------------------------------------- /man/figures/add_rasterizer.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plotly/rasterly/HEAD/man/figures/add_rasterizer.gif -------------------------------------------------------------------------------- /man/figures/grid_rasterizer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plotly/rasterly/HEAD/man/figures/grid_rasterizer.png -------------------------------------------------------------------------------- /man/figures/plotly_rasterizer.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plotly/rasterly/HEAD/man/figures/plotly_rasterizer.gif -------------------------------------------------------------------------------- /pkgdown/favicon/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plotly/rasterly/HEAD/pkgdown/favicon/favicon-16x16.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plotly/rasterly/HEAD/pkgdown/favicon/favicon-32x32.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plotly/rasterly/HEAD/pkgdown/favicon/apple-touch-icon.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | .Ruserdata 5 | src/*.o 6 | src/*.so 7 | src/*.dll 8 | doc 9 | Meta 10 | -------------------------------------------------------------------------------- /docs/pkgdown.yml: -------------------------------------------------------------------------------- 1 | pandoc: '2.6' 2 | pkgdown: 1.4.1 3 | pkgdown_sha: ~ 4 | articles: 5 | introduction: introduction.html 6 | 7 | -------------------------------------------------------------------------------- /docs/reference/figures/add_rasterizer.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plotly/rasterly/HEAD/docs/reference/figures/add_rasterizer.gif -------------------------------------------------------------------------------- /vignettes/images/introduction/anyAgg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plotly/rasterly/HEAD/vignettes/images/introduction/anyAgg.png -------------------------------------------------------------------------------- /vignettes/images/introduction/darkBg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plotly/rasterly/HEAD/vignettes/images/introduction/darkBg.png -------------------------------------------------------------------------------- /vignettes/images/introduction/ggUber.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plotly/rasterly/HEAD/vignettes/images/introduction/ggUber.png -------------------------------------------------------------------------------- /vignettes/images/introduction/meanAgg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plotly/rasterly/HEAD/vignettes/images/introduction/meanAgg.png -------------------------------------------------------------------------------- /docs/reference/figures/grid_rasterizer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plotly/rasterly/HEAD/docs/reference/figures/grid_rasterizer.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-60x60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plotly/rasterly/HEAD/pkgdown/favicon/apple-touch-icon-60x60.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-76x76.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plotly/rasterly/HEAD/pkgdown/favicon/apple-touch-icon-76x76.png -------------------------------------------------------------------------------- /vignettes/images/introduction/uberBasic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plotly/rasterly/HEAD/vignettes/images/introduction/uberBasic.png -------------------------------------------------------------------------------- /vignettes/images/introduction/uberColor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plotly/rasterly/HEAD/vignettes/images/introduction/uberColor.png -------------------------------------------------------------------------------- /docs/articles/images/introduction/anyAgg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plotly/rasterly/HEAD/docs/articles/images/introduction/anyAgg.png -------------------------------------------------------------------------------- /docs/articles/images/introduction/darkBg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plotly/rasterly/HEAD/docs/articles/images/introduction/darkBg.png -------------------------------------------------------------------------------- /docs/articles/images/introduction/ggUber.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plotly/rasterly/HEAD/docs/articles/images/introduction/ggUber.png -------------------------------------------------------------------------------- /docs/articles/images/introduction/meanAgg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plotly/rasterly/HEAD/docs/articles/images/introduction/meanAgg.png -------------------------------------------------------------------------------- /docs/reference/figures/plotly_rasterizer.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plotly/rasterly/HEAD/docs/reference/figures/plotly_rasterizer.gif -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-120x120.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plotly/rasterly/HEAD/pkgdown/favicon/apple-touch-icon-120x120.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-152x152.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plotly/rasterly/HEAD/pkgdown/favicon/apple-touch-icon-152x152.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-180x180.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plotly/rasterly/HEAD/pkgdown/favicon/apple-touch-icon-180x180.png -------------------------------------------------------------------------------- /vignettes/images/introduction/image2data.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plotly/rasterly/HEAD/vignettes/images/introduction/image2data.png -------------------------------------------------------------------------------- /vignettes/introduction.html.asis: -------------------------------------------------------------------------------- 1 | %\VignetteEngine{knitr::knitr} 2 | %\VignetteIndexEntry{Introduction} 3 | %\usepackage[utf8]{inputenc} 4 | -------------------------------------------------------------------------------- /docs/articles/images/introduction/image2data.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plotly/rasterly/HEAD/docs/articles/images/introduction/image2data.png -------------------------------------------------------------------------------- /docs/articles/images/introduction/uberBasic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plotly/rasterly/HEAD/docs/articles/images/introduction/uberBasic.png -------------------------------------------------------------------------------- /docs/articles/images/introduction/uberColor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plotly/rasterly/HEAD/docs/articles/images/introduction/uberColor.png -------------------------------------------------------------------------------- /vignettes/images/introduction/add_rasterizer.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plotly/rasterly/HEAD/vignettes/images/introduction/add_rasterizer.gif -------------------------------------------------------------------------------- /vignettes/images/introduction/uberColorCover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plotly/rasterly/HEAD/vignettes/images/introduction/uberColorCover.png -------------------------------------------------------------------------------- /R/reexports.R: -------------------------------------------------------------------------------- 1 | #' @importFrom magrittr '%>%' 2 | #' @export 3 | magrittr::'%>%' 4 | 5 | #' @importFrom ggplot2 aes 6 | #' @export 7 | ggplot2::aes 8 | -------------------------------------------------------------------------------- /docs/articles/images/introduction/add_rasterizer.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plotly/rasterly/HEAD/docs/articles/images/introduction/add_rasterizer.gif -------------------------------------------------------------------------------- /docs/articles/images/introduction/uberColorCover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plotly/rasterly/HEAD/docs/articles/images/introduction/uberColorCover.png -------------------------------------------------------------------------------- /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^doc$ 4 | ^Meta$ 5 | .gitignore 6 | .travis.yml 7 | _pkgdown.yml 8 | README.md 9 | NEWS.md 10 | codecov.yml 11 | ^_pkgdown\.yml$ 12 | ^docs$ 13 | ^pkgdown$ 14 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | comment: false 2 | 3 | coverage: 4 | status: 5 | project: 6 | default: 7 | target: auto 8 | threshold: 1% 9 | patch: 10 | default: 11 | target: auto 12 | threshold: 1% 13 | -------------------------------------------------------------------------------- /man/is.rasterly.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/is_rasterly.R 3 | \name{is.rasterly} 4 | \alias{is.rasterly} 5 | \title{Is \code{rasterly}} 6 | \usage{ 7 | is.rasterly(x) 8 | } 9 | \arguments{ 10 | \item{x}{a \code{rasterly} object} 11 | } 12 | \description{ 13 | Reports whether x is a \code{rasterly} object. 14 | } 15 | -------------------------------------------------------------------------------- /.Rproj.user/84277BCC/cpp-complilation-config: -------------------------------------------------------------------------------- 1 | { 2 | "args" : [ 3 | "-IE:/Rstudio/resources/libclang/builtin-headers/5.0.2", 4 | "-IE:/Rstudio/resources/libclang/builtin-headers/libc++/5.0.2", 5 | "-IE:/R-3.6.3/library/Rcpp/include", 6 | "-std=gnu++11", 7 | "-IE:/R-3.6.3/include", 8 | "-DNDEBUG" 9 | ], 10 | "hash" : "1587558325", 11 | "is_cpp" : true, 12 | "pch" : "Rcpp" 13 | } -------------------------------------------------------------------------------- /rasterly.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: ISO8859-1 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | BuildType: Package 16 | PackageUseDevtools: Yes 17 | PackageInstallArgs: --no-multiarch --with-keep.source 18 | PackageRoxygenize: rd,collate,namespace,vignette 19 | -------------------------------------------------------------------------------- /man/is.rasterlyBuild.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/is_rasterly.R 3 | \name{is.rasterlyBuild} 4 | \alias{is.rasterlyBuild} 5 | \title{Is \code{rasterlyBuild}} 6 | \usage{ 7 | is.rasterlyBuild(x) 8 | } 9 | \arguments{ 10 | \item{x}{a \code{rasterly} object} 11 | } 12 | \description{ 13 | Reports whether x is a \code{rasterlyBuild} object. In other word, it helps to define 14 | whether this object has been passed through `rasterly_build` 15 | } 16 | -------------------------------------------------------------------------------- /man/reexports.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/reexports.R 3 | \docType{import} 4 | \name{reexports} 5 | \alias{reexports} 6 | \alias{\%>\%} 7 | \alias{aes} 8 | \title{Objects exported from other packages} 9 | \keyword{internal} 10 | \description{ 11 | These objects are imported from other packages. Follow the links 12 | below to see their documentation. 13 | 14 | \describe{ 15 | \item{ggplot2}{\code{\link[ggplot2]{aes}}} 16 | 17 | \item{magrittr}{\code{\link[magrittr]{\%>\%}}} 18 | }} 19 | 20 | -------------------------------------------------------------------------------- /R/color_setting.R: -------------------------------------------------------------------------------- 1 | get_rgb_num <- function(color) { 2 | rgb_num <- grDevices::col2rgb(color) 3 | list( 4 | red = rgb_num['red', ], 5 | green = rgb_num['green', ], 6 | blue = rgb_num['blue', ] 7 | ) 8 | } 9 | 10 | interpolation <- function(..., span = NULL) { 11 | 12 | if(is.null(span)) span <- 50 # default setting in approx 13 | args <- list(...) 14 | lapply(args, 15 | function(arg){ 16 | stats::approx(x = arg, n = span)[['y']] 17 | }) 18 | 19 | } 20 | 21 | gg_color_hue <- function(n) { 22 | hues <- seq(15, 375, length = n + 1) 23 | grDevices::hcl(h = hues, l = 65, c = 100)[1:n] 24 | } 25 | -------------------------------------------------------------------------------- /R/is_rasterly.R: -------------------------------------------------------------------------------- 1 | #' @title Is \code{rasterly} 2 | #' @description Reports whether x is a \code{rasterly} object. 3 | #' @param x a \code{rasterly} object 4 | #' @export 5 | is.rasterly <- function(x) { 6 | inherits(x, "rasterly") 7 | } 8 | 9 | #' @title Is \code{rasterlyBuild} 10 | #' @description Reports whether x is a \code{rasterlyBuild} object. In other word, it helps to define 11 | #' whether this object has been passed through `rasterly_build` 12 | #' @param x a \code{rasterly} object 13 | #' @export 14 | is.rasterlyBuild <- function(x) { 15 | inherits(x, "rasterlyBuild") 16 | } 17 | 18 | is.rasterlyLayer <- function(x) { 19 | inherits(x, "rasterlyLayer") 20 | } 21 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | addons: 2 | apt: 3 | packages: 4 | - libtk-img 5 | - mesa-common-dev 6 | - libglu1-mesa-dev 7 | - freeglut3-dev 8 | - libssl-dev 9 | - libcurl4-gnutls-dev 10 | - libxml2-dev 11 | - xvfb 12 | 13 | sudo: false 14 | 15 | language: r 16 | r_github_packages: 17 | - r-lib/covr 18 | 19 | before_install: 20 | - export DISPLAY=':99.0' 21 | - Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 & 22 | - R -q -e 'install.packages(c("Rcpp", "ggplot2", "data.table", "plotly", "magrittr","rlang","testthat","knitr","rmarkdown", "png"))' 23 | 24 | cache: packages 25 | 26 | r: 27 | - release 28 | - devel 29 | 30 | after_success: 31 | - Rscript -e 'covr::codecov()' -------------------------------------------------------------------------------- /R/unreported_functions.R: -------------------------------------------------------------------------------- 1 | ################################ Unreported functions in `ggplot2` and `plotly` 2 | # Reason: Avoid `:::` to pass R CMD check 3 | 4 | ## Unexported functions in ggplot2 5 | new_aes <- getFromNamespace("new_aes", "ggplot2") 6 | 7 | new_aesthetic <- getFromNamespace("new_aesthetic", "ggplot2") 8 | 9 | ## Unexported functions in plotly 10 | add_trace_classed <- function(p, class = "plotly_polygon", ...) { 11 | p <- plotly::add_trace(p, ...) 12 | nAttrs <- length(p$x$attrs) 13 | p$x$attrs[[nAttrs]] <- prefix_class(p$x$attrs[[nAttrs]], class) 14 | p 15 | } 16 | 17 | prefix_class <- function(x, y) { 18 | structure(x, class = unique(c(y, class(x)))) 19 | } 20 | -------------------------------------------------------------------------------- /man/color_map.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/colorMaps.R 3 | \docType{data} 4 | \name{color_map} 5 | \alias{color_map} 6 | \alias{fire_map} 7 | \alias{viridis_map} 8 | \alias{hourColors_map} 9 | \title{Supplemental color maps for rasterly} 10 | \format{ 11 | An object of class \code{character} of length 256. 12 | 13 | An object of class \code{character} of length 256. 14 | 15 | An object of class \code{character} of length 24. 16 | } 17 | \usage{ 18 | fire_map 19 | 20 | viridis_map 21 | 22 | hourColors_map 23 | } 24 | \description{ 25 | Hex codes for the color map. 26 | Used in setting argument \code{color} in \code{rasterly} or \code{rasterly} layers. 27 | } 28 | \keyword{datasets} 29 | -------------------------------------------------------------------------------- /docs/link.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 13 | -------------------------------------------------------------------------------- /man/rasterly_build.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rasterly_build.R 3 | \name{rasterly_build} 4 | \alias{rasterly_build} 5 | \title{rasterly_build} 6 | \usage{ 7 | rasterly_build(rastObj) 8 | } 9 | \arguments{ 10 | \item{rastObj}{A rasterly object. It should be a list of environments composed of a \code{rasterly()} and 11 | several \code{rasterly_...} layers.} 12 | } 13 | \description{ 14 | Produce a rasterly object and return the raster information required to produce an image 15 | } 16 | \note{ 17 | A rasterly object will never be produced until \code{rasterly_build()} is called. 18 | } 19 | \examples{ 20 | r <- data.frame(x = rnorm(1e5), y = rnorm(1e5)) \%>\% 21 | rasterly(mapping = aes(x = x, y = y)) \%>\% 22 | rasterly_points(color = fire_map) 23 | str(r) 24 | p <- rasterly_build(r) 25 | str(p) 26 | } 27 | \seealso{ 28 | \link{rasterly}, \link{rasterly_points}, \link{[.rasterly}, \link{[<-.rasterly} 29 | } 30 | -------------------------------------------------------------------------------- /R/get_aggregation_sd.R: -------------------------------------------------------------------------------- 1 | get_aggregation.var <- function(plot_width, plot_height, aesthetics, 2 | x_range, y_range, xlim, ylim, 3 | func, glyph, group_by_data_table, ...) { 4 | 5 | if(is.null(aesthetics$on)) stop("No `on` argument was provided. Which variable should be used for sum of square differences from the mean?") 6 | is_size <- !is.null(aesthetics$size) 7 | is_color <- !is.null(aesthetics$color) 8 | 9 | aesthetics$on <- stats::sd(aesthetics$on) 10 | get_aggregation.sum(plot_width = plot_width, 11 | plot_height = plot_height, 12 | aesthetics = aesthetics, 13 | x_range = x_range, 14 | y_range = y_range, 15 | xlim = xlim, 16 | ylim = ylim, 17 | func = NULL, 18 | glyph = glyph, 19 | group_by_data_table = group_by_data_table, ...) 20 | } 21 | -------------------------------------------------------------------------------- /R/get_aggregation_var.R: -------------------------------------------------------------------------------- 1 | get_aggregation.var <- function(plot_width, plot_height, aesthetics, 2 | x_range, y_range, xlim, ylim, 3 | func, glyph, group_by_data_table, ...) { 4 | 5 | if(is.null(aesthetics$on)) stop("No `on` argument was provided. Which variable should be used for sum of square differences from the mean?") 6 | is_size <- !is.null(aesthetics$size) 7 | is_color <- !is.null(aesthetics$color) 8 | 9 | aesthetics$on <- stats::var(aesthetics$on) 10 | get_aggregation.sum(plot_width = plot_width, 11 | plot_height = plot_height, 12 | aesthetics = aesthetics, 13 | x_range = x_range, 14 | y_range = y_range, 15 | xlim = xlim, 16 | ylim = ylim, 17 | func = NULL, 18 | glyph = glyph, 19 | group_by_data_table = group_by_data_table, ...) 20 | } 21 | -------------------------------------------------------------------------------- /R/get_aggregation_m2.R: -------------------------------------------------------------------------------- 1 | get_aggregation.m2 <- function(plot_width, plot_height, aesthetics, 2 | x_range, y_range, xlim, ylim, 3 | func, glyph, group_by_data_table, ...) { 4 | 5 | if(is.null(aesthetics$on)) stop("No `on` argument was provided. Which variable should be used for sum of square differences from the mean?") 6 | is_size <- !is.null(aesthetics$size) 7 | is_color <- !is.null(aesthetics$color) 8 | 9 | aesthetics$on <- (aesthetics$on - mean(aesthetics$on))^2 10 | get_aggregation.sum(plot_width = plot_width, 11 | plot_height = plot_height, 12 | aesthetics = aesthetics, 13 | x_range = x_range, 14 | y_range = y_range, 15 | xlim = xlim, 16 | ylim = ylim, 17 | func = NULL, 18 | glyph = glyph, 19 | group_by_data_table = group_by_data_table, ...) 20 | } 21 | -------------------------------------------------------------------------------- /man/grapes-set-grapes.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/merge_operator.R 3 | \name{\%<-\%} 4 | \alias{\%<-\%} 5 | \title{Merge operator} 6 | \usage{ 7 | x \%<-\% y 8 | } 9 | \arguments{ 10 | \item{x}{A named list or vector} 11 | 12 | \item{y}{A named list or vector. Any duplicated names are detected in x will be covered by y} 13 | } 14 | \value{ 15 | a list 16 | } 17 | \description{ 18 | Merge two objects from right to left. 19 | } 20 | \examples{ 21 | # two lists 22 | x <- list(a = 1, b = "foo", c = 3) 23 | y <- list(b = 2, d = 4) 24 | x \%<-\% y 25 | y \%<-\% x 26 | 27 | # one list and one vector 28 | x <- c(foo = 1, bar = 2) 29 | y <- list(foo = "foo") 30 | x \%<-\% y 31 | y \%<-\% x 32 | 33 | # two vectors 34 | x <- c(a = 1, b = "foo", c = 3) 35 | y <- c(b = 2, d = 4) 36 | x \%<-\% y 37 | y \%<-\% x 38 | 39 | # duplicated names in x 40 | x <- list(a = 1, b = "foo", b = 3) 41 | y <- list(b = 2, d = 4) 42 | x \%<-\% y 43 | y \%<-\% x # be careful, since "3" will cover on "foo" in x, then on "2" in y 44 | 45 | } 46 | -------------------------------------------------------------------------------- /R/rasterize_points.R: -------------------------------------------------------------------------------- 1 | #' @title rasterize_points 2 | #' @description Points layer for "rasterly". Deprecated now, please use \code{rasterly_points} instead. 3 | #' @seealso \link{rasterly_points} 4 | #' @inheritParams rasterly_points 5 | #' @export 6 | rasterize_points <- function(rastObj, 7 | data = NULL, 8 | mapping = aes(), 9 | ..., 10 | xlim = NULL, 11 | ylim = NULL, 12 | max_size = NULL, 13 | reduction_func = NULL, 14 | layout = NULL, 15 | glyph = NULL, 16 | group_by_data_table = NULL, 17 | inherit.aes = TRUE) { 18 | warning("`rasterize_points` is deprecated. Please use `rasterly_points`.") 19 | rasterly_points( 20 | rastObj, 21 | data, 22 | mapping, 23 | ..., 24 | xlim, 25 | ylim, 26 | max_size, 27 | reduction_func, 28 | layout, 29 | glyph, 30 | group_by_data_table, 31 | inherit.aes 32 | ) 33 | } -------------------------------------------------------------------------------- /man/rasterly_guides.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rasterly_guides.R 3 | \name{rasterly_guides} 4 | \alias{rasterly_guides} 5 | \title{rasterly_guides} 6 | \usage{ 7 | rasterly_guides( 8 | rastObj, 9 | x_pretty = NULL, 10 | y_pretty = NULL, 11 | panel_background = "grey92", 12 | panel_line = "white" 13 | ) 14 | } 15 | \arguments{ 16 | \item{rastObj}{A "rasterly" object.} 17 | 18 | \item{x_pretty}{The pretty on x. Compute a sequence of about n+1 equally spaced 'round' values 19 | which cover the range of the values in x. If it is not provided, \code{x_pretty} will 20 | be generated by the x range} 21 | 22 | \item{y_pretty}{The pretty on y.} 23 | 24 | \item{panel_background}{Panel background.} 25 | 26 | \item{panel_line}{Panel line color} 27 | } 28 | \description{ 29 | Guides layer for "rasterly". 30 | } 31 | \details{ 32 | When an image has a 'complicated' background, the drawing time increases significantly. 33 | So it is not recommended. A suggestion to draw grid guides is to transform image data to a data frame 34 | via \link{image2data}, then use \code{ggplot} or \code{plotly} to display. 35 | } 36 | \seealso{ 37 | \link{ggRasterly} 38 | } 39 | -------------------------------------------------------------------------------- /man/image2data.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/image2data.R 3 | \name{image2data} 4 | \alias{image2data} 5 | \title{Image raster to data frame.} 6 | \usage{ 7 | image2data(x, background = "white", x_range = NULL, y_range = NULL) 8 | } 9 | \arguments{ 10 | \item{x}{It could be a rasterly object or a raster image.} 11 | 12 | \item{background}{The background of image raster.} 13 | 14 | \item{x_range}{The range represents image width.} 15 | 16 | \item{y_range}{The range represents image height.} 17 | } 18 | \value{ 19 | a \code{data.table} object 20 | } 21 | \description{ 22 | Transform a image raster to a data frame. 23 | } 24 | \examples{ 25 | x <- rnorm(1000, mean = 10) 26 | y <- rnorm(1000, mean = 20) 27 | color <- sample(1:5, 1000, replace = TRUE) 28 | rastObj <- data.frame(x = x, y = y, color = color) \%>\% 29 | rasterly(mapping = aes(x = x, y = y, color = color)) \%>\% 30 | rasterly_points() 31 | p <- rasterly_build(rastObj) 32 | dt <- image2data(p) 33 | if(requireNamespace("ggplot2")) { 34 | # Note that each point represents a single pixel in the image 35 | ggplot2::ggplot(dt, mapping = aes(x = x, y = y)) + 36 | ggplot2::geom_point(color = dt$color, size = 0.5) 37 | } 38 | } 39 | \seealso{ 40 | \link{ggRasterly} 41 | } 42 | -------------------------------------------------------------------------------- /man/rasterly-package.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rasterly-package.R 3 | \docType{package} 4 | \name{rasterly-package} 5 | \alias{rasterly-package} 6 | \alias{_PACKAGE} 7 | \title{rasterly: Easily and Rapidly Generate Raster Image Data with Support for 'Plotly.js'} 8 | \description{ 9 | \if{html}{\figure{logo.png}{options: align='right' alt='logo' width='120'}} 10 | 11 | It aims to easily and rapidly generate raster data in R, even for very large datasets, with an aesthetics-based mapping syntax that should be familiar to users of the \code{ggplot2} package. While \code{rasterly} does not attempt to reproduce the full functionality of the \code{Datashader} graphics pipeline system for Python, the \code{rasterly} API has several core elements in common with that software package. 12 | } 13 | \seealso{ 14 | Useful links: 15 | \itemize{ 16 | \item Report bugs at \url{https://github.com/plotly/rasterly/issues} 17 | } 18 | 19 | } 20 | \author{ 21 | \strong{Maintainer}: Zehao Xu \email{z267xu@uwaterloo.ca} 22 | 23 | Other contributors: 24 | \itemize{ 25 | \item Ryan Patrick Kyle \email{ryan@plot.ly} (\href{https://orcid.org/0000-0001-5829-9867}{ORCID}) [contributor] 26 | \item Plotly Technologies [copyright holder] 27 | } 28 | 29 | } 30 | \keyword{internal} 31 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: rasterly 2 | Title: Easily and Rapidly Generate Raster Image Data with Support for 'Plotly.js' 3 | Version: 0.2.0 4 | Authors@R: c(person("Zehao", "Xu", role = c("aut", "cre"), email = "z267xu@uwaterloo.ca"), person("Ryan Patrick", "Kyle", role = c("ctb"), comment = c(ORCID = "0000-0001-5829-9867"), email = "ryan@plot.ly"), person(family = "Plotly Technologies", role = "cph")) 5 | Description: It aims to easily and rapidly generate raster data in R, even for very large datasets, with an aesthetics-based mapping syntax that should be familiar to users of the \code{ggplot2} package. While \code{rasterly} does not attempt to reproduce the full functionality of the \code{Datashader} graphics pipeline system for Python, the \code{rasterly} API has several core elements in common with that software package. 6 | LinkingTo: Rcpp 7 | License: MIT + file LICENSE 8 | Encoding: UTF-8 9 | ByteCompile: true 10 | KeepSource: true 11 | BugReports: https://github.com/plotly/rasterly/issues 12 | Depends: 13 | R (>= 3.4.0), 14 | methods, 15 | Rcpp 16 | Imports: 17 | data.table, 18 | rlang, 19 | plotly, 20 | ggplot2, 21 | magrittr, 22 | grid, 23 | stats 24 | Suggests: 25 | covr, 26 | testthat, 27 | knitr, 28 | rmarkdown, 29 | lubridate 30 | LazyData: true 31 | RoxygenNote: 7.1.0 32 | VignetteBuilder: knitr 33 | -------------------------------------------------------------------------------- /R/merge_operator.R: -------------------------------------------------------------------------------- 1 | #' @title Merge operator 2 | #' @description Merge two objects from right to left. 3 | #' @usage x \%<-\% y 4 | #' 5 | #' @return a list 6 | #' 7 | #' @param x A named list or vector 8 | #' @param y A named list or vector. Any duplicated names are detected in x will be covered by y 9 | #' 10 | #' @examples 11 | #' # two lists 12 | #' x <- list(a = 1, b = "foo", c = 3) 13 | #' y <- list(b = 2, d = 4) 14 | #' x %<-% y 15 | #' y %<-% x 16 | #' 17 | #' # one list and one vector 18 | #' x <- c(foo = 1, bar = 2) 19 | #' y <- list(foo = "foo") 20 | #' x %<-% y 21 | #' y %<-% x 22 | #' 23 | #' # two vectors 24 | #' x <- c(a = 1, b = "foo", c = 3) 25 | #' y <- c(b = 2, d = 4) 26 | #' x %<-% y 27 | #' y %<-% x 28 | #' 29 | #' # duplicated names in x 30 | #' x <- list(a = 1, b = "foo", b = 3) 31 | #' y <- list(b = 2, d = 4) 32 | #' x %<-% y 33 | #' y %<-% x # be careful, since "3" will cover on "foo" in x, then on "2" in y 34 | #' 35 | #' @export 36 | `%<-%` <- function(x, y) { 37 | if(is.null(names(x)) || is.null(names(y))) 38 | return(c(x,y)) 39 | else { 40 | 41 | if(!is.list(x)) x <- as.list(x) 42 | if(!is.list(y)) y <- as.list(y) 43 | 44 | merged_list <- c(x, y) 45 | list_names <- names(merged_list) 46 | merged_list[duplicated(list_names, fromLast = TRUE)] <- NULL 47 | 48 | return(merged_list[unique(list_names)]) 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | S3method("[",rasterly) 4 | S3method("[<-",rasterly) 5 | S3method(image2data,matrix) 6 | S3method(image2data,raster) 7 | S3method(image2data,rasterly) 8 | S3method(plot,rasterly) 9 | S3method(print,rasterly) 10 | S3method(rasterly_build,default) 11 | S3method(rasterly_build,rasterly) 12 | S3method(rasterly_build,rasterlyBuild) 13 | S3method(rplot,default) 14 | export("%<-%") 15 | export("%>%") 16 | export(add_rasterly_heatmap) 17 | export(add_rasterly_image) 18 | export(aes) 19 | export(fire_map) 20 | export(ggRasterly) 21 | export(grid.rasterly) 22 | export(hourColors_map) 23 | export(image2data) 24 | export(is.rasterly) 25 | export(is.rasterlyBuild) 26 | export(plotRasterly) 27 | export(rasterize_points) 28 | export(rasterly) 29 | export(rasterlyGrob) 30 | export(rasterly_build) 31 | export(rasterly_guides) 32 | export(rasterly_points) 33 | export(rplot) 34 | export(viridis_map) 35 | import(Rcpp) 36 | import(grid) 37 | import(methods) 38 | import(rlang) 39 | importFrom(data.table,data.table) 40 | importFrom(ggplot2,aes) 41 | importFrom(grDevices,as.raster) 42 | importFrom(grDevices,col2rgb) 43 | importFrom(grDevices,extendrange) 44 | importFrom(grDevices,hcl) 45 | importFrom(grDevices,rgb) 46 | importFrom(magrittr,'%>%') 47 | importFrom(stats,approx) 48 | importFrom(stats,ecdf) 49 | importFrom(stats,na.omit) 50 | importFrom(stats,setNames) 51 | useDynLib(rasterly) 52 | -------------------------------------------------------------------------------- /man/extract.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/extract.R 3 | \name{extract} 4 | \alias{extract} 5 | \alias{[.rasterly} 6 | \alias{[<-.rasterly} 7 | \title{Extract or replace parts of a \code{rasterly} object} 8 | \usage{ 9 | \method{[}{rasterly}(x, name) 10 | 11 | \method{[}{rasterly}(x, name, ...) <- value 12 | } 13 | \arguments{ 14 | \item{x}{Object from which to extract element(s) or in which to replace element(s).} 15 | 16 | \item{name}{Character. A literal string to be extracted from \code{x}. See details for more information.} 17 | 18 | \item{...}{(missing) or NULL.} 19 | 20 | \item{value}{values to replace; typically an array-like R object of a similar class as x.} 21 | } 22 | \description{ 23 | The \code{extract} function provides functionality for updating existing \code{rasterly} objects. 24 | } 25 | \details{ 26 | Available names: 27 | \itemize{ 28 | \item{Aggregation: }{"data", "mapping", "plot_width", "plot_height", "range", "x_range", 29 | "y_range", "xlim", "ylim", "aesthetics", "reduction_func", "glyph", 30 | "max_size", "group_by_data_table", "drop_data", "variable_check"} 31 | \item{Display: }{"background", "color", "alpha", "span", 32 | "show_raster", "layout"} 33 | } 34 | 35 | Set \code{level} in \code{...}. \code{level} is numeric used for specifing level of `rasterly` object to modify; 36 | default is 1 for the parent layer (\code{rasterly()}). 37 | } 38 | \examples{ 39 | library(rasterly) 40 | r <- rasterly( 41 | data = data.frame(x = 1:1e4, y = runif(1e4), category = sample(1:4, 1e4, replace = TRUE)), 42 | mapping = aes(x = x, y = y) 43 | ) \%>\% 44 | rasterly_points(xlim = c(1, 5000)) \%>\% 45 | rasterly_points( 46 | mapping = aes(x = x, y = y, color = category), 47 | xlim = c(5001, 1e4) 48 | ) 49 | r["mapping"] 50 | r["xlim"] 51 | 52 | # reassign parent `rasterly()` mapping 53 | r["mapping"] <- aes(x = x, y = y, color = category) 54 | r["mapping"] 55 | 56 | # reassign all mapping systems 57 | r["mapping", level = 1:length(r)] <- aes(x = x, y = y) 58 | r["mapping"] 59 | } 60 | -------------------------------------------------------------------------------- /R/rasterly_guides.R: -------------------------------------------------------------------------------- 1 | #' @title rasterly_guides 2 | #' @description Guides layer for "rasterly". 3 | #' @param rastObj A "rasterly" object. 4 | #' @param x_pretty The pretty on x. Compute a sequence of about n+1 equally spaced 'round' values 5 | #' which cover the range of the values in x. If it is not provided, \code{x_pretty} will 6 | #' be generated by the x range 7 | #' @param y_pretty The pretty on y. 8 | #' @param panel_background Panel background. 9 | #' @param panel_line Panel line color 10 | #' @details When an image has a 'complicated' background, the drawing time increases significantly. 11 | #' So it is not recommended. A suggestion to draw grid guides is to transform image data to a data frame 12 | #' via \link{image2data}, then use \code{ggplot} or \code{plotly} to display. 13 | #' @seealso \link{ggRasterly} 14 | #' @export 15 | rasterly_guides <- function(rastObj, 16 | x_pretty = NULL, 17 | y_pretty = NULL, 18 | panel_background = "grey92", 19 | panel_line = "white") { 20 | 21 | x_pretty <- get_x_pretty(envir = rastObj$rasterly_env, x_pretty) 22 | y_pretty <- get_x_pretty(envir = rastObj$rasterly_env, y_pretty) 23 | 24 | panel_background <- get_panel_background(envir = rastObj$rasterly_env, panel_background) 25 | panel_line <- get_panel_line(envir = rastObj$rasterly_env, panel_line) 26 | 27 | p <- structure( 28 | list(rasterly_guides = environment()), 29 | class = c("rasterlyGuides") 30 | ) 31 | rastObj <- c( 32 | rastObj, 33 | p 34 | ) 35 | class(rastObj) <- c("rasterly") 36 | invisible(return(rastObj)) 37 | } 38 | 39 | 40 | get_panel_background <- function(envir, panel_background) { 41 | 42 | parent_args <- .get("args", envir = envir) 43 | panel_background <- panel_background %||% parent_args$panel_background %||% "grey92" 44 | 45 | return(panel_background) 46 | } 47 | 48 | get_panel_line <- function(envir, panel_line) { 49 | 50 | parent_args <- .get("args", envir = envir) 51 | panel_line <- panel_line %||% parent_args$panel_line %||% "white" 52 | 53 | return(panel_line) 54 | } -------------------------------------------------------------------------------- /docs/docsearch.js: -------------------------------------------------------------------------------- 1 | $(function() { 2 | 3 | // register a handler to move the focus to the search bar 4 | // upon pressing shift + "/" (i.e. "?") 5 | $(document).on('keydown', function(e) { 6 | if (e.shiftKey && e.keyCode == 191) { 7 | e.preventDefault(); 8 | $("#search-input").focus(); 9 | } 10 | }); 11 | 12 | $(document).ready(function() { 13 | // do keyword highlighting 14 | /* modified from https://jsfiddle.net/julmot/bL6bb5oo/ */ 15 | var mark = function() { 16 | 17 | var referrer = document.URL ; 18 | var paramKey = "q" ; 19 | 20 | if (referrer.indexOf("?") !== -1) { 21 | var qs = referrer.substr(referrer.indexOf('?') + 1); 22 | var qs_noanchor = qs.split('#')[0]; 23 | var qsa = qs_noanchor.split('&'); 24 | var keyword = ""; 25 | 26 | for (var i = 0; i < qsa.length; i++) { 27 | var currentParam = qsa[i].split('='); 28 | 29 | if (currentParam.length !== 2) { 30 | continue; 31 | } 32 | 33 | if (currentParam[0] == paramKey) { 34 | keyword = decodeURIComponent(currentParam[1].replace(/\+/g, "%20")); 35 | } 36 | } 37 | 38 | if (keyword !== "") { 39 | $(".contents").unmark({ 40 | done: function() { 41 | $(".contents").mark(keyword); 42 | } 43 | }); 44 | } 45 | } 46 | }; 47 | 48 | mark(); 49 | }); 50 | }); 51 | 52 | /* Search term highlighting ------------------------------*/ 53 | 54 | function matchedWords(hit) { 55 | var words = []; 56 | 57 | var hierarchy = hit._highlightResult.hierarchy; 58 | // loop to fetch from lvl0, lvl1, etc. 59 | for (var idx in hierarchy) { 60 | words = words.concat(hierarchy[idx].matchedWords); 61 | } 62 | 63 | var content = hit._highlightResult.content; 64 | if (content) { 65 | words = words.concat(content.matchedWords); 66 | } 67 | 68 | // return unique words 69 | var words_uniq = [...new Set(words)]; 70 | return words_uniq; 71 | } 72 | 73 | function updateHitURL(hit) { 74 | 75 | var words = matchedWords(hit); 76 | var url = ""; 77 | 78 | if (hit.anchor) { 79 | url = hit.url_without_anchor + '?q=' + escape(words.join(" ")) + '#' + hit.anchor; 80 | } else { 81 | url = hit.url + '?q=' + escape(words.join(" ")); 82 | } 83 | 84 | return url; 85 | } 86 | -------------------------------------------------------------------------------- /R/get_aggregation_any.R: -------------------------------------------------------------------------------- 1 | get_aggregation.any <- function(plot_width, plot_height, aesthetics, 2 | x_range, y_range, xlim, ylim, 3 | func, glyph, group_by_data_table, ...) { 4 | 5 | is_on <- !is.null(aesthetics$on) 6 | is_size <- !is.null(aesthetics$size) 7 | is_color <- !is.null(aesthetics$color) 8 | 9 | L <- if(group_by_data_table) { 10 | 11 | display <- aesthetics[, 12 | list( 13 | display = list( 14 | aggregation_anyCpp(plot_width = plot_width, plot_height = plot_height, 15 | x_range = x_range, y_range = y_range, 16 | xlim = xlim, ylim = ylim, 17 | x = x, 18 | y = y, 19 | on = if(is_on) on else numeric(0), 20 | size = if(is_size) size else numeric(0), 21 | glyph = glyph) 22 | ) 23 | ), 24 | by = if(is_color) color else NULL] 25 | remove(aesthetics) 26 | display$display 27 | } else { 28 | if(is_color) { 29 | levels <- unique(aesthetics$color) 30 | # agg_sumCpp return a list 31 | agg_anyCpp(L = lapply(1:length(levels), function(i) matrix(0, nrow = plot_height, ncol = plot_width)), 32 | levels = levels, 33 | category = aesthetics$color, 34 | plot_width = plot_width, plot_height = plot_height, 35 | x_range = x_range, y_range = y_range, 36 | xlim = xlim, ylim = ylim, 37 | x = aesthetics$x, 38 | y = aesthetics$y, 39 | on = if(is_on) aesthetics$on else numeric(0), 40 | size = if(is_size) aesthetics$size else numeric(0), 41 | glyph = glyph) 42 | } else { 43 | list( 44 | aggregation_anyCpp(plot_width = plot_width, plot_height = plot_height, 45 | x_range = x_range, y_range = y_range, 46 | xlim = xlim, ylim = ylim, 47 | x = aesthetics$x, 48 | y = aesthetics$y, 49 | on = if(is_on) aesthetics$on else numeric(0), 50 | size = if(is_size) aesthetics$size else numeric(0), 51 | glyph = glyph) 52 | ) 53 | } 54 | } 55 | return(L) 56 | } 57 | -------------------------------------------------------------------------------- /R/get_aggregation_max.R: -------------------------------------------------------------------------------- 1 | get_aggregation.max <- function(plot_width, plot_height, aesthetics, 2 | x_range, y_range, xlim, ylim, 3 | func, glyph, group_by_data_table, ...) { 4 | 5 | if(is.null(aesthetics$on)) stop("No `on` argument was provided. Which variable should be used when calculating the maximum value for aggregation?") 6 | is_size <- !is.null(aesthetics$size) 7 | is_color <- !is.null(aesthetics$color) 8 | 9 | L <- if(group_by_data_table) { 10 | 11 | display <- aesthetics[, 12 | list( 13 | display = list( 14 | aggregation_maxCpp(plot_width = plot_width, plot_height = plot_height, 15 | x_range = x_range, y_range = y_range, 16 | xlim = xlim, ylim = ylim, 17 | x = x, 18 | y = y, 19 | on = on, 20 | size = if(is_size) size else numeric(0), 21 | glyph = glyph) 22 | ) 23 | ), 24 | by = if(is_color) color else NULL] 25 | remove(aesthetics) 26 | display$display 27 | } else { 28 | 29 | if(is_color) { 30 | levels <- unique(aesthetics$color) 31 | # agg_sumCpp return a list 32 | agg_maxCpp(L = lapply(1:length(levels), function(i) matrix(0, nrow = plot_height, ncol = plot_width)), 33 | levels = levels, 34 | category = aesthetics$color, 35 | plot_width = plot_width, plot_height = plot_height, 36 | x_range = x_range, y_range = y_range, 37 | xlim = xlim, ylim = ylim, 38 | x = aesthetics$x, 39 | y = aesthetics$y, 40 | on = aesthetics$on, 41 | size = if(is_size) aesthetics$size else numeric(0), 42 | glyph = glyph) 43 | } else { 44 | list( 45 | aggregation_maxCpp(plot_width = plot_width, plot_height = plot_height, 46 | x_range = x_range, y_range = y_range, 47 | xlim = xlim, ylim = ylim, 48 | x = aesthetics$x, 49 | y = aesthetics$y, 50 | on = aesthetics$on, 51 | size = if(is_size) aesthetics$size else numeric(0), 52 | glyph = glyph) 53 | ) 54 | } 55 | } 56 | return(L) 57 | } 58 | -------------------------------------------------------------------------------- /R/get_aggregation_min.R: -------------------------------------------------------------------------------- 1 | get_aggregation.min <- function(plot_width, plot_height, aesthetics, 2 | x_range, y_range, xlim, ylim, 3 | func, glyph, group_by_data_table, ...) { 4 | 5 | if(is.null(aesthetics$on)) stop("No `on` argument was provided. Which variable should be used when calculating the minimum value for aggregation?") 6 | is_size <- !is.null(aesthetics$size) 7 | is_color <- !is.null(aesthetics$color) 8 | 9 | L <- if(group_by_data_table) { 10 | 11 | display <- aesthetics[, 12 | list( 13 | display = list( 14 | aggregation_minCpp(plot_width = plot_width, plot_height = plot_height, 15 | x_range = x_range, y_range = y_range, 16 | xlim = xlim, ylim = ylim, 17 | x = x, 18 | y = y, 19 | on = on, 20 | size = if(is_size) size else numeric(0), 21 | glyph = glyph) 22 | ) 23 | ), 24 | by = if(is_color) color else NULL] 25 | remove(aesthetics) 26 | display$display 27 | } else { 28 | 29 | if(is_color) { 30 | levels <- unique(aesthetics$color) 31 | # agg_sumCpp return a list 32 | agg_minCpp(L = lapply(1:length(levels), function(i) matrix(0, nrow = plot_height, ncol = plot_width)), 33 | levels = levels, 34 | category = aesthetics$color, 35 | plot_width = plot_width, plot_height = plot_height, 36 | x_range = x_range, y_range = y_range, 37 | xlim = xlim, ylim = ylim, 38 | x = aesthetics$x, 39 | y = aesthetics$y, 40 | on = aesthetics$on, 41 | size = if(is_size) aesthetics$size else numeric(0), 42 | glyph = glyph) 43 | } else { 44 | list( 45 | aggregation_minCpp(plot_width = plot_width, plot_height = plot_height, 46 | x_range = x_range, y_range = y_range, 47 | xlim = xlim, ylim = ylim, 48 | x = aesthetics$x, 49 | y = aesthetics$y, 50 | on = aesthetics$on, 51 | size = if(is_size) aesthetics$size else numeric(0), 52 | glyph = glyph) 53 | ) 54 | } 55 | } 56 | return(L) 57 | } 58 | -------------------------------------------------------------------------------- /R/extract.R: -------------------------------------------------------------------------------- 1 | #' @title Extract or replace parts of a \code{rasterly} object 2 | #' @name extract 3 | #' @description The \code{extract} function provides functionality for updating existing \code{rasterly} objects. 4 | #' @param x Object from which to extract element(s) or in which to replace element(s). 5 | #' @param name Character. A literal string to be extracted from \code{x}. See details for more information. 6 | #' 7 | #' @details Available names: 8 | #' \itemize{ 9 | #' \item{Aggregation: }{"data", "mapping", "plot_width", "plot_height", "range", "x_range", 10 | #' "y_range", "xlim", "ylim", "aesthetics", "reduction_func", "glyph", 11 | #' "max_size", "group_by_data_table", "drop_data", "variable_check"} 12 | #' \item{Display: }{"background", "color", "alpha", "span", 13 | #' "show_raster", "layout"} 14 | #' } 15 | #' 16 | #' @examples 17 | #' library(rasterly) 18 | #' r <- rasterly( 19 | #' data = data.frame(x = 1:1e4, y = runif(1e4), category = sample(1:4, 1e4, replace = TRUE)), 20 | #' mapping = aes(x = x, y = y) 21 | #' ) %>% 22 | #' rasterly_points(xlim = c(1, 5000)) %>% 23 | #' rasterly_points( 24 | #' mapping = aes(x = x, y = y, color = category), 25 | #' xlim = c(5001, 1e4) 26 | #' ) 27 | #' r["mapping"] 28 | #' r["xlim"] 29 | #' 30 | #' # reassign parent `rasterly()` mapping 31 | #' r["mapping"] <- aes(x = x, y = y, color = category) 32 | #' r["mapping"] 33 | #' 34 | #' # reassign all mapping systems 35 | #' r["mapping", level = 1:length(r)] <- aes(x = x, y = y) 36 | #' r["mapping"] 37 | #' @export 38 | `[.rasterly` <- function(x, name) { 39 | # x is executed 40 | if(is.rasterlyBuild(x)) { 41 | getElement(x, name) 42 | } else { 43 | # x is an unexecuted list of environments 44 | lapply(x, 45 | function(envir) { 46 | .get(name, envir = envir) 47 | }) 48 | } 49 | } 50 | 51 | #' @param ... (missing) or NULL. 52 | #' @param value values to replace; typically an array-like R object of a similar class as x. 53 | #' @rdname extract 54 | #' @details 55 | #' Set \code{level} in \code{...}. \code{level} is numeric used for specifing level of `rasterly` object to modify; 56 | #' default is 1 for the parent layer (\code{rasterly()}). 57 | #' 58 | #' @export 59 | `[<-.rasterly` <- function(x, name, ..., value) { 60 | 61 | args <- list(...) 62 | level <- args$level %||% 1 63 | 64 | # x is executed 65 | if(is.rasterlyBuild(x)) { 66 | warning("Replacing elements of existing `rasterlyBuild` objects is not supported.", call. = FALSE) 67 | do.call(`$<-`, list(x = x, name = name, value = value)) 68 | } else { 69 | # x is an unexecuted list of environments 70 | for(l in level) { 71 | assign(name, value, envir = x[[l]]) 72 | } 73 | invisible(return(x)) 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /R/get_aggregation_last.R: -------------------------------------------------------------------------------- 1 | get_aggregation.last <- function(plot_width, plot_height, aesthetics, 2 | x_range, y_range, xlim, ylim, 3 | func, glyph, group_by_data_table, ...) { 4 | 5 | if(is.null(aesthetics$on)) stop("No `on` argument was provided. Which variable should be used to specify the last value encountered for aggregation?") 6 | is_size <- !is.null(aesthetics$size) 7 | is_color <- !is.null(aesthetics$color) 8 | 9 | L <- if(group_by_data_table) { 10 | 11 | display <- aesthetics[, 12 | list( 13 | display = list( 14 | aggregation_lastCpp(plot_width = plot_width, plot_height = plot_height, 15 | x_range = x_range, y_range = y_range, 16 | xlim = xlim, ylim = ylim, 17 | x = x, 18 | y = y, 19 | on = on, 20 | size = if(is_size) size else numeric(0), 21 | glyph = glyph) 22 | ) 23 | ), 24 | by = if(is_color) color else NULL] 25 | remove(aesthetics) 26 | display$display 27 | } else { 28 | 29 | if(is_color) { 30 | levels <- unique(aesthetics$color) 31 | # agg_sumCpp return a list 32 | agg_lastCpp(L = lapply(1:length(levels), function(i) matrix(0, nrow = plot_height, ncol = plot_width)), 33 | levels = levels, 34 | category = aesthetics$color, 35 | plot_width = plot_width, plot_height = plot_height, 36 | x_range = x_range, y_range = y_range, 37 | xlim = xlim, ylim = ylim, 38 | x = aesthetics$x, 39 | y = aesthetics$y, 40 | on = aesthetics$on, 41 | size = if(is_size) aesthetics$size else numeric(0), 42 | glyph = glyph) 43 | } else { 44 | list( 45 | aggregation_lastCpp(plot_width = plot_width, plot_height = plot_height, 46 | x_range = x_range, y_range = y_range, 47 | xlim = xlim, ylim = ylim, 48 | x = aesthetics$x, 49 | y = aesthetics$y, 50 | on = aesthetics$on, 51 | size = if(is_size) aesthetics$size else numeric(0), 52 | glyph = glyph) 53 | ) 54 | } 55 | } 56 | return(L) 57 | } 58 | -------------------------------------------------------------------------------- /R/get_aggregation_first.R: -------------------------------------------------------------------------------- 1 | get_aggregation.first <- function(plot_width, plot_height, aesthetics, 2 | x_range, y_range, xlim, ylim, 3 | func, glyph, group_by_data_table, ...) { 4 | 5 | 6 | if(is.null(aesthetics$on)) stop("No `on` argument was provided. Which variable should be used to return the first value encountered for aggregation?") 7 | is_size <- !is.null(aesthetics$size) 8 | is_color <- !is.null(aesthetics$color) 9 | 10 | L <- if(group_by_data_table) { 11 | 12 | display <- aesthetics[, 13 | list( 14 | display = list( 15 | aggregation_firstCpp(plot_width = plot_width, plot_height = plot_height, 16 | x_range = x_range, y_range = y_range, 17 | xlim = xlim, ylim = ylim, 18 | x = x, 19 | y = y, 20 | on = on, 21 | size = if(is_size) size else numeric(0), 22 | glyph = glyph) 23 | ) 24 | ), 25 | by = if(is_color) color else NULL] 26 | remove(aesthetics) 27 | display$display 28 | } else { 29 | 30 | if(is_color) { 31 | levels <- unique(aesthetics$color) 32 | # agg_sumCpp return a list 33 | agg_firstCpp(L = lapply(1:length(levels), function(i) matrix(0, nrow = plot_height, ncol = plot_width)), 34 | levels = levels, 35 | category = aesthetics$color, 36 | plot_width = plot_width, plot_height = plot_height, 37 | x_range = x_range, y_range = y_range, 38 | xlim = xlim, ylim = ylim, 39 | x = aesthetics$x, 40 | y = aesthetics$y, 41 | on = aesthetics$on, 42 | size = if(is_size) aesthetics$size else numeric(0), 43 | glyph = glyph) 44 | } else { 45 | list( 46 | aggregation_firstCpp(plot_width = plot_width, plot_height = plot_height, 47 | x_range = x_range, y_range = y_range, 48 | xlim = xlim, ylim = ylim, 49 | x = aesthetics$x, 50 | y = aesthetics$y, 51 | on = aesthetics$on, 52 | size = if(is_size) aesthetics$size else numeric(0), 53 | glyph = glyph) 54 | ) 55 | } 56 | } 57 | return(L) 58 | } 59 | -------------------------------------------------------------------------------- /R/get_aggregation_sum.R: -------------------------------------------------------------------------------- 1 | get_aggregation <- function(plot_width, plot_height, aesthetics, 2 | x_range, y_range, xlim, ylim, func, glyph, group_by_data_table, ...) { 3 | UseMethod("get_aggregation", func) 4 | } 5 | 6 | get_aggregation.sum <- function(plot_width, plot_height, aesthetics, 7 | x_range, y_range, xlim, ylim, 8 | func, glyph, group_by_data_table, ...) { 9 | 10 | is_on <- !is.null(aesthetics$on) 11 | is_size <- !is.null(aesthetics$size) 12 | is_color <- !is.null(aesthetics$color) 13 | 14 | L <- if(group_by_data_table) { 15 | 16 | display <- aesthetics[, 17 | list( 18 | display = list( 19 | aggregation_sumCpp(plot_width = plot_width, plot_height = plot_height, 20 | x_range = x_range, y_range = y_range, 21 | xlim = xlim, ylim = ylim, 22 | x = x, 23 | y = y, 24 | on = if(is_on) on else numeric(0), 25 | size = if(is_size) size else numeric(0), 26 | glyph = glyph) 27 | ) 28 | ), 29 | by = if(is_color) color else NULL] 30 | remove(aesthetics) 31 | display$display 32 | } else { 33 | 34 | if(is_color) { 35 | levels <- unique(aesthetics$color) 36 | # agg_sumCpp return a list 37 | agg_sumCpp(L = lapply(1:length(levels), function(i) matrix(0, nrow = plot_height, ncol = plot_width)), 38 | levels = levels, 39 | category = aesthetics$color, 40 | plot_width = plot_width, plot_height = plot_height, 41 | x_range = x_range, y_range = y_range, 42 | xlim = xlim, ylim = ylim, 43 | x = aesthetics$x, 44 | y = aesthetics$y, 45 | on = if(is_on) aesthetics$on else numeric(0), 46 | size = if(is_size) aesthetics$size else numeric(0), 47 | glyph = glyph) 48 | } else { 49 | list( 50 | aggregation_sumCpp(plot_width = plot_width, plot_height = plot_height, 51 | x_range = x_range, y_range = y_range, 52 | xlim = xlim, ylim = ylim, 53 | x = aesthetics$x, 54 | y = aesthetics$y, 55 | on = if(is_on) aesthetics$on else numeric(0), 56 | size = if(is_size) aesthetics$size else numeric(0), 57 | glyph = glyph) 58 | ) 59 | } 60 | } 61 | 62 | return(L) 63 | } 64 | -------------------------------------------------------------------------------- /man/rasterize_points.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rasterize_points.R 3 | \name{rasterize_points} 4 | \alias{rasterize_points} 5 | \title{rasterize_points} 6 | \usage{ 7 | rasterize_points( 8 | rastObj, 9 | data = NULL, 10 | mapping = aes(), 11 | ..., 12 | xlim = NULL, 13 | ylim = NULL, 14 | max_size = NULL, 15 | reduction_func = NULL, 16 | layout = NULL, 17 | glyph = NULL, 18 | group_by_data_table = NULL, 19 | inherit.aes = TRUE 20 | ) 21 | } 22 | \arguments{ 23 | \item{rastObj}{A \code{rasterly} object.} 24 | 25 | \item{data}{A \code{data.frame} or \code{function} with an argument \code{x}, specifying the dataset to use for plotting. If \code{data} 26 | is \code{NULL}, the \code{data} argument provided to \code{rasterly} may be passed through.} 27 | 28 | \item{mapping}{Default list of aesthetic mappings to use for plot. If provided and \code{inherit.aes = TRUE}, it will be 29 | stacked on top of the mappings passed to \code{rasterly}.} 30 | 31 | \item{...}{Pass-through arguments provided by \code{rasterly}.} 32 | 33 | \item{xlim}{Vector of type numeric. X limits in this layer.} 34 | 35 | \item{ylim}{Vector of type numeric. Y limits in this layer.} 36 | 37 | \item{max_size}{Numeric. When size changes, the upper bound of the number of pixels over which to spread a single observation.} 38 | 39 | \item{reduction_func}{Function. A reduction function is used to aggregate data points into their pixel representations. Currently 40 | supported reduction operators are \code{sum}, \code{any}, \code{mean}, \code{m2}, \code{first}, \code{last}, \code{min} and \code{max}. Default is \code{sum}. See details.} 41 | 42 | \item{layout}{Character. The method used to generate layouts for multiple images. The default is \code{weighted}. Useful for categorical 43 | data (i.e. "color" is provided via \code{aes()}). \code{weighted} specifies that the final raster should be a weighted combination of each 44 | (categorical) aggregation matrix. Conversely, \code{cover} indicates that the afterwards objects will be drawn on top of 45 | the previous ones.} 46 | 47 | \item{glyph}{Character. Currently, only "circle" and "square" are supported; as the \code{size} of the pixels increases, how should they 48 | spread out -- should the pattern be circular or square? Other glyphs may be added in the future.} 49 | 50 | \item{group_by_data_table}{Logical. Default is \code{TRUE}; when "color" is provided via \code{aes()}, the "group by" operation may be 51 | perfromed within \code{data.table} or natively within \code{rasterly}. Generally, \code{group_by_data_table = TRUE} is faster, but for very 52 | large datasets grouping within \code{rasterly} may offer better performance.} 53 | 54 | \item{inherit.aes}{If \code{FALSE}, overrides the default aesthetics, rather than combining with them.} 55 | } 56 | \description{ 57 | Points layer for "rasterly". Deprecated now, please use \code{rasterly_points} instead. 58 | } 59 | \seealso{ 60 | \link{rasterly_points} 61 | } 62 | -------------------------------------------------------------------------------- /R/image2data.R: -------------------------------------------------------------------------------- 1 | #' @title Image raster to data frame. 2 | #' @description Transform a image raster to a data frame. 3 | #' @param x It could be a rasterly object or a raster image. 4 | #' @param background The background of image raster. 5 | #' @param x_range The range represents image width. 6 | #' @param y_range The range represents image height. 7 | #' @return a \code{data.table} object 8 | #' @seealso \link{ggRasterly} 9 | #' @examples 10 | #' x <- rnorm(1000, mean = 10) 11 | #' y <- rnorm(1000, mean = 20) 12 | #' color <- sample(1:5, 1000, replace = TRUE) 13 | #' rastObj <- data.frame(x = x, y = y, color = color) %>% 14 | #' rasterly(mapping = aes(x = x, y = y, color = color)) %>% 15 | #' rasterly_points() 16 | #' p <- rasterly_build(rastObj) 17 | #' dt <- image2data(p) 18 | #' if(requireNamespace("ggplot2")) { 19 | #' # Note that each point represents a single pixel in the image 20 | #' ggplot2::ggplot(dt, mapping = aes(x = x, y = y)) + 21 | #' ggplot2::geom_point(color = dt$color, size = 0.5) 22 | #' } 23 | #' @export 24 | image2data <- function(x, 25 | background = "white", 26 | x_range = NULL, 27 | y_range = NULL) { 28 | if(missing(x)) stop("Missing x") 29 | UseMethod("image2data", x) 30 | } 31 | 32 | #' @export 33 | image2data.rasterly <- function(x, 34 | background = "white", 35 | x_range = NULL, 36 | y_range = NULL) { 37 | 38 | if(!is.rasterlyBuild(x)) x <- rasterly_build(x) 39 | 40 | imageData(image = as.matrix(x$image), 41 | background = background %||% x$background, 42 | x_range = x_range %||% x$x_range, 43 | y_range = y_range %||% x$y_range) 44 | } 45 | 46 | #' @export 47 | image2data.raster <- function(x, 48 | background = "white", 49 | x_range = NULL, 50 | y_range = NULL) { 51 | imageData(image = as.matrix(x), 52 | background = background, 53 | x_range = x_range, 54 | y_range = y_range) 55 | } 56 | 57 | #' @export 58 | image2data.matrix <- function(x, 59 | background = "white", 60 | x_range = NULL, 61 | y_range = NULL) { 62 | 63 | imageData(image = x, 64 | background = background, 65 | x_range = x_range, 66 | y_range = y_range) 67 | } 68 | 69 | imageData <- function(image, 70 | background = "white", 71 | x_range = NULL, 72 | y_range = NULL) { 73 | dimM <- dim(image) 74 | height <- dimM[1] 75 | width <- dimM[2] 76 | 77 | x_range <- x_range %||% c(1, width) 78 | y_range <- y_range %||% c(1, height) 79 | 80 | y <- rep(seq(from = y_range[2], to = y_range[1], length.out = height), width) 81 | x <- rep(seq(from = x_range[1], to = x_range[2], length.out = width), each = height) 82 | 83 | not_blank_id <- c(!image %in% background) 84 | y <- y[not_blank_id] 85 | x <- x[not_blank_id] 86 | image <- image[not_blank_id] 87 | data.table::data.table( 88 | x = x, 89 | y = y, 90 | color = image 91 | ) 92 | } -------------------------------------------------------------------------------- /R/add_rasterly_image.R: -------------------------------------------------------------------------------- 1 | #' @param color Numeric vector or expression. Pixel color for each observation, to be passed on to \code{aes()}. 2 | #' @rdname add_rasterly 3 | #' @export 4 | 5 | add_rasterly_image <- function(p, 6 | x = NULL, y = NULL, z = NULL, ..., 7 | data = NULL, inherit = TRUE, 8 | color = NULL, on = NULL, size = NULL) { 9 | if (inherit) { 10 | x <- x %||% p$x$attrs[[1]][["x"]] 11 | y <- y %||% p$x$attrs[[1]][["y"]] 12 | z <- z %||% p$x$attrs[[1]][["z"]] 13 | } 14 | 15 | args <- list(...) 16 | rasterly_args <- c( 17 | union(methods::formalArgs(rasterly), methods::formalArgs(rasterly_points)), 18 | "color_map", 19 | "colour_map", 20 | "color_key", 21 | "colour_key" 22 | ) 23 | args[rasterly_args] <- NULL 24 | 25 | if (is.null(z)) { 26 | # produce z by rasterly 27 | ### set vars 28 | data <- data %||% p$x$visdat[[1]]() 29 | on <- on %||% p$x$attrs[[1]][["on"]] 30 | size <- size %||% p$x$attrs[[1]][["size"]] 31 | color <- color %||% p$x$attrs[[1]][["color"]] 32 | 33 | ### set mappings 34 | mapping_names <- c("x", "y", "on", "size", "color") 35 | names(mapping_names) <- mapping_names 36 | mapping <- aes() 37 | expressions <- stats::setNames( 38 | list(x, y, on, size, color), 39 | mapping_names 40 | ) 41 | 42 | for(i in 1:length(mapping_names)) { 43 | exp <- expressions[[i]] 44 | 45 | if(is.null(exp)) { 46 | mapping_names[i] <- NA 47 | } else { 48 | if(rlang::is_formula(exp)) { 49 | the_parse <- sub("~", "", rlang::expr_text(exp)) %>% 50 | rlang::parse_expr() 51 | mapping[[i]] <- rlang::quo(!!the_parse) 52 | } else if(is.numeric(exp)) { 53 | data[[mapping_names[i]]] <- exp 54 | mapping[[i]] <- rlang::quo(!!rlang::parse_expr(mapping_names[i])) 55 | } else { 56 | stop("'size' ,'on' and 'color' are neither `quote` nor a numerical value.", call. = FALSE) 57 | } 58 | } 59 | } 60 | 61 | mapping <- Filter(Negate(is.null), mapping) 62 | names(mapping) <- stats::na.omit(mapping_names) 63 | 64 | data %>% 65 | rasterly(mapping = mapping, 66 | show_raster = TRUE, 67 | ...) %>% 68 | rasterly_points() %>% 69 | rasterly_build() -> rastObj 70 | data <- NULL 71 | 72 | z <- rastObj$image 73 | dimZ <- dim(z) 74 | 75 | do.call( 76 | plotly::add_image, 77 | c( 78 | list( 79 | p = p, 80 | z = z, 81 | x0 = rastObj$x_range[1], 82 | dx = diff(rastObj$x_range)/dimZ[2], 83 | y0 = rastObj$y_range[2], 84 | dy = -diff(rastObj$y_range)/dimZ[1], 85 | data = data, 86 | inherit = inherit 87 | ), 88 | args 89 | ) 90 | ) %>% plotly::layout( 91 | xaxis = list(range = rastObj$x_range), 92 | yaxis = list(range = rastObj$y_range) 93 | ) 94 | 95 | } else { 96 | message("If z is provided, `plotly::add_image` will be implemented.") 97 | do.call( 98 | plotly::add_image, 99 | c( 100 | list( 101 | p = p, 102 | z = z, 103 | data = data, 104 | inherit = inherit 105 | ), 106 | args 107 | ) 108 | ) 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /R/utils.R: -------------------------------------------------------------------------------- 1 | # it is equivalent to R.utils::isZero 2 | isZero <- function (x, neps = 1, eps = .Machine$double.eps, ...) { 3 | if (is.character(eps)) { 4 | eps <- match.arg(eps, choices = c("double.eps", "single.eps")) 5 | if (eps == "double.eps") { 6 | eps <- .Machine$double.eps 7 | } 8 | else if (eps == "single.eps") { 9 | eps <- sqrt(.Machine$double.eps) 10 | } 11 | } 12 | (abs(x) < neps * eps) 13 | } 14 | 15 | 16 | mbind <- function(new_mapping = aes(), mapping) { 17 | 18 | if (!missing(mapping) && !inherits(mapping, "uneval") && 19 | !missing(new_mapping) && !inherits(new_mapping, "uneval")) { 20 | stop("Mapping should be created with `aes()`.", call. = FALSE) 21 | } 22 | 23 | new_aes(new_mapping %<-% mapping) 24 | } 25 | 26 | .get <- function(x, envir = as.environment(-1), mode = "any", ifnotfound, 27 | inherits = FALSE) { 28 | 29 | if(missing(ifnotfound)) 30 | ifnotfound <- list(NULL) 31 | 32 | mget(x = x, envir = envir, mode = mode, 33 | ifnotfound = ifnotfound, 34 | inherits = inherits)[[x]] 35 | 36 | } 37 | 38 | 39 | get_cdf <- function(M, zeroIgnored = TRUE, ...) { 40 | 41 | if(missing(M)) stop("No matrix found; get_cdf requires a valid matrix M is passed.") 42 | args <- list(...) 43 | 44 | cdf <- if(zeroIgnored) { 45 | 46 | which_is_not_zero <- if(!is.null(args$which_is_not_zero)) args$which_is_not_zero else M != 0 47 | stats::ecdf(M[which_is_not_zero]) 48 | } else { 49 | stats::ecdf(M) 50 | } 51 | 52 | return(cdf) 53 | } 54 | 55 | color_warning <- function(envir, args) { 56 | 57 | color_key <- .get("color_key", envir = envir) 58 | color_map <- .get("color_map", envir = envir) 59 | 60 | if(is.null(color_key) && is.null(color_map)) { 61 | 62 | if(!is.null(args$color_key)) 63 | warning("`color_key` is deprecated now. Please use `color` instead.", call. = FALSE) 64 | 65 | if(!is.null(args$color_map)) 66 | warning("`color_map` is deprecated now. Please use `color` instead.", call. = FALSE) 67 | 68 | } else NULL # warning has already been generated 69 | } 70 | 71 | get_varnames <- function(var_names, dir) { 72 | varnames <- switch(dir, 73 | "x" = var_names[grepl("x", names(var_names))][1], 74 | "y" = var_names[grepl("y", names(var_names))][1] 75 | ) 76 | return(varnames) 77 | } 78 | 79 | 80 | remove_missing_matrix <- function(m, value = 0) { 81 | m[!rowSums(!is.finite(m)),] 82 | # replace all non-finite values with 0 83 | m[!is.finite(m)] <- value 84 | m 85 | } 86 | 87 | rename_mapping <- function(mapping) { 88 | 89 | if (!missing(mapping) && !inherits(mapping, "uneval")) { 90 | stop("Mapping should be created with `aes()`.", call. = FALSE) 91 | } 92 | 93 | names_mapping <- names(mapping) 94 | if(length(names_mapping) == 0 || !"colour" %in% names_mapping) return(mapping) 95 | names_mapping[names_mapping == "colour"] <- "color" 96 | names(mapping) <- names_mapping 97 | return(mapping) 98 | } 99 | 100 | # Pass R CMD check --as-cran 101 | # Suggestion from https://stackoverflow.com/questions/9439256/how-can-i-handle-r-cmd-check-no-visible-binding-for-global-variable-notes-when 102 | # The reason to set globalVariables instead of define x, y, ... is because 103 | # the cost of extraction values from large data is very heavy 104 | if(getRversion() >= "3.1.0") utils::globalVariables(c("..mapping_names", "size", "x", "y", "on", "color", ".")) 105 | -------------------------------------------------------------------------------- /man/rplot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rplot.R 3 | \name{rplot} 4 | \alias{rplot} 5 | \alias{rplot.default} 6 | \title{Rasterly plot} 7 | \usage{ 8 | rplot(x, y = NULL, ...) 9 | 10 | \method{rplot}{default}( 11 | x, 12 | y = NULL, 13 | ..., 14 | plot_width = 600, 15 | plot_height = 600, 16 | x_range = NULL, 17 | y_range = NULL, 18 | background = "white", 19 | reduction_func = NULL, 20 | layout = NULL, 21 | glyph = NULL 22 | ) 23 | } 24 | \arguments{ 25 | \item{x, y}{Coordinates x, y for the plot.} 26 | 27 | \item{...}{Other \code{rasterly} arguments to pass through.} 28 | 29 | \item{plot_width}{Integer. The width of the image to plot; must be a positive integer. A higher value indicates a higher resolution.} 30 | 31 | \item{plot_height}{Integer. The height of the image to plot; must be a positive integer. A higher value indicates a higher resolution.} 32 | 33 | \item{x_range}{Vector of type numeric. The range of \code{x}; it can be used to clip the image. For larger datasets, providing \code{x_range} 34 | may result in improved performance.} 35 | 36 | \item{y_range}{Vector of type numeric. The range of \code{y}; it can be used to clip the image. For larger datasets, providing \code{y_range} 37 | may result in improved performance.} 38 | 39 | \item{background}{Character. The background color of the image to plot.} 40 | 41 | \item{reduction_func}{Function. A reduction function is used to aggregate data points into their pixel representations. Currently 42 | supported reduction operators are \code{sum}, \code{any}, \code{mean}, \code{m2}, \code{first}, \code{last}, \code{min} and \code{max}. Default is \code{sum}. See details.} 43 | 44 | \item{layout}{Character. The method used to generate layouts for multiple images. The default is \code{weighted}. Useful for categorical 45 | data (i.e. "color" is provided via \code{aes()}). \code{weighted} specifies that the final raster should be a weighted combination of each 46 | (categorical) aggregation matrix. Conversely, \code{cover} indicates that the afterwards objects will be drawn on top of 47 | the previous ones.} 48 | 49 | \item{glyph}{Character. Currently, only "circle" and "square" are supported; as the \code{size} of the pixels increases, how should they 50 | spread out -- should the pattern be circular or square? Other glyphs may be added in the future.} 51 | } 52 | \description{ 53 | \code{rplot} is created to generate \code{rasterly} plot quickly but with base 54 | \link{plot} design. It is convenient but lacks flexibility and \link{rasterly} is highly 55 | recommended for a more versatile method. 56 | } 57 | \details{ 58 | \code{rasterly} arguments are passed through via \code{...}. But some of them are noticeable. 59 | \itemize{ 60 | \item{\code{size}: Size can be either a specified size (1, 2, 3, etc) or a mapping variable. Since \code{rasterly} does not provide 61 | point to point display, if the length of input \code{size} is the same with the length of \code{x} (or \code{y}). It will be treated as 62 | a mapping variable.} 63 | \item{\code{color}: Color can be either a color map vector or a mapping variable. If the length of \code{color} is equal to the length of 64 | \code{x} (or \code{y}). It will be treated as a mapping variable.} 65 | \item{\code{on}: On is always treated as a mapping variable.} 66 | } 67 | } 68 | \examples{ 69 | if(requireNamespace("ggplot2")) { 70 | library(ggplot2) 71 | # `color` represents a variable here 72 | with(diamonds, 73 | rplot(x = carat, y = price, color = color) 74 | ) 75 | # `color` represents an actual color vector 76 | with(diamonds, 77 | rplot(x = carat, y = price, color = fire_map) 78 | ) 79 | } 80 | } 81 | \seealso{ 82 | \link{rasterly} \link{rasterly_points} 83 | } 84 | -------------------------------------------------------------------------------- /docs/pkgdown.js: -------------------------------------------------------------------------------- 1 | /* http://gregfranko.com/blog/jquery-best-practices/ */ 2 | (function($) { 3 | $(function() { 4 | 5 | $('.navbar-fixed-top').headroom(); 6 | 7 | $('body').css('padding-top', $('.navbar').height() + 10); 8 | $(window).resize(function(){ 9 | $('body').css('padding-top', $('.navbar').height() + 10); 10 | }); 11 | 12 | $('body').scrollspy({ 13 | target: '#sidebar', 14 | offset: 60 15 | }); 16 | 17 | $('[data-toggle="tooltip"]').tooltip(); 18 | 19 | var cur_path = paths(location.pathname); 20 | var links = $("#navbar ul li a"); 21 | var max_length = -1; 22 | var pos = -1; 23 | for (var i = 0; i < links.length; i++) { 24 | if (links[i].getAttribute("href") === "#") 25 | continue; 26 | // Ignore external links 27 | if (links[i].host !== location.host) 28 | continue; 29 | 30 | var nav_path = paths(links[i].pathname); 31 | 32 | var length = prefix_length(nav_path, cur_path); 33 | if (length > max_length) { 34 | max_length = length; 35 | pos = i; 36 | } 37 | } 38 | 39 | // Add class to parent
YEAR: 2019 126 | COPYRIGHT HOLDER: Plotly, Inc. 127 |128 | 129 |
2 |
3 | [](https://travis-ci.org/z267xu/rasterly)
4 | [](https://codecov.io/gh/z267xu/rasterly?branch=master)
5 | [](https://cran.r-project.org/web/packages/rasterly/index.html)
6 | [](https://cran.r-project.org/package=rasterly)
7 |
8 | Easily and rapidly generate raster data in R, even for larger volumes of data, with an aesthetics-based mapping syntax that should be familiar to users of the `ggplot2` package.
9 |
10 | While `rasterly` does not attempt to reproduce the full functionality of the Datashader graphics pipeline system for Python, the `rasterly` API has several core elements in common with that software package. Combined with Plotly.js and the `plotly` package, `rasterly` enables analysts to generate interactive figures which are responsive enough to embed into web applications.
11 |
12 | Documentation: [https://z267xu.github.io/rasterly/](https://z267xu.github.io/rasterly/)
13 |
14 | ## Importing datasets for use with rasterly
15 |
16 | There are several ways to import large datasets into R for use with `rasterly`; one option is the `data.table` package (https://cran.r-project.org/web/packages/data.table/vignettes/datatable-intro.html).
17 |
18 | * csv file:
19 | ```
20 | library(data.table)
21 | data <- data.table::fread("yourpath/somefile.csv") # or a link
22 | ```
23 |
24 | * parquet file:
25 | Apache Parquet is a column-oriented, open-source format which offers efficient data compression. There are a few options in R for importing Parquet data. One of these is the [`arrow`](https://cran.r-project.org/web/packages/arrow/index.html) package, now available on CRAN.
26 |
27 | The package must build Apache Arrow first, so it may take a few minutes to install the first time around.
28 |
29 | ```
30 | library(arrow)
31 | parquet_data <- read_parquet("somefile.parquet")
32 | # returns a data.frame if sparklyr is not loaded, otherwise it will be a tibble
33 | # to obtain an ordinary data.frame, some slight postprocessing may be required
34 | # parquet_data <- base::as.data.frame(parquet_data)
35 | ```
36 |
37 | * fst file:
38 | The [fst package](https://www.fstpackage.org/) is an excellent option for extremely fast serialization of large data frames in R. In addition to rapid compression using LZ4 and ZSTD, it provides support for multithreading to parallelize operations.
39 |
40 | ```
41 | library(fst)
42 | fst_data <- read.fst("somefile.fst")
43 | ```
44 |
45 | ## Installing the package
46 |
47 | The `rasterly` package is now available from CRAN, and the most recent release will always be available on GitHub. To install the CRAN package:
48 | ```
49 | install.packages("rasterly")
50 | ```
51 | To install the current version available via GitHub instead:
52 | ```
53 | remotes::install_github("plotly/rasterly")
54 | ```
55 |
56 | ## Visualizing data with `rasterly`
57 |
58 | `rasterly` is inspired by the [`datashader`](http://datashader.org/getting_started/index.html) package available for Python. Both provide the capability to generate raster data for rapid rendering of graphics for even very large datasets.
59 |
60 | In terms of performance, `datashader` is faster but `rasterly` is comparable. `rasterly` aims to provide a user-friendly interface to generate raster data for use with the `plotly` package; it cannot be used for plotting or rendering figures on its own.
61 |
62 | #### Producing an interactive graph with the plotly package
63 |
64 | To illustrate the basic functionality provided by the package, we'll start by retrieving data on Uber trips taken in New York City from April 1st until September 30th of 2014. The dataset includes 4,533,327 observations.
65 |
66 | ```
67 | # Load New York Uber data
68 | ridesRaw_1 <- "https://raw.githubusercontent.com/plotly/datasets/master/uber-rides-data1.csv" %>%
69 | data.table::fread(stringsAsFactors = FALSE)
70 | ridesRaw_2 <- "https://raw.githubusercontent.com/plotly/datasets/master/uber-rides-data2.csv" %>%
71 | data.table::fread(stringsAsFactors = FALSE)
72 | ridesRaw_3 <- "https://raw.githubusercontent.com/plotly/datasets/master/uber-rides-data3.csv" %>%
73 | data.table::fread(stringsAsFactors = FALSE)
74 | ridesDf <- list(ridesRaw_1, ridesRaw_2, ridesRaw_3) %>%
75 | data.table::rbindlist()
76 | ```
77 |
78 | Now that the data are loaded, we can pass them to `plot_ly` and pipe the output into `add_rasterly`:
79 |
80 | ```
81 | plot_ly(ridesDf, x = ~Lat, y = ~Lon) %>%
82 | add_rasterly_heatmap()
83 | ```
84 | 
85 |
86 | #### General usage
87 |
88 | Pass the data into `rasterly`:
89 | ```
90 | ridesDf %>%
91 | rasterly(mapping = aes(x = Lat, y = Lon)) %>%
92 | rasterly_points() -> p
93 | p
94 | # or use simplied `rplot`
95 | with(ridesDf,
96 | rplot(x = Lat, y = Lon)
97 | )
98 | ```
99 | 
100 |
101 | Note that, `p` is a list of environments. The display info can be accessed through
102 | ```
103 | r <- rasterly_build(p)
104 | str(r)
105 | ```
106 |
107 | "r" contains image raster and other useful info (like numeric aggregation matrices) required to produce the image but it does **not** provide any graphs.
108 |
109 | ## Example use in interactive web applications
110 |
111 | The Uber NYC Rasterizer application in our Dash Gallery provides a simple live demo of the `rasterly` package in action. Check it out [here](https://dash-gallery.plotly.host/dashr-uber-rasterizer/)!
112 |
113 |
114 |
115 | A second [Dash for R](https://github.com/plotly/dashR) application to visualize (a much larger) dataset from the US Census Bureau is also [available](https://github.com/plotly/rasterly/tree/master/apps/UScensus).
116 |
--------------------------------------------------------------------------------
/docs/articles/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 | reexports.RdThese objects are imported from other packages. Follow the links 137 | below to see their documentation.
138 |%>%
rasterly — is.rasterly • rasterlycolor_map.RdHex codes for the color map.
131 | Used in setting argument color in rasterly or rasterly layers.
fire_map 135 | 136 | viridis_map 137 | 138 | hourColors_map139 | 140 | 141 |
An object of class character of length 256.
An object of class character of length 256.
An object of class character of length 24.
rasterlyBuild — is.rasterlyBuild • rasterlyrasterlyBuildis.rasterlyBuild.RdReports whether x is a rasterlyBuild object. In other word, it helps to define
131 | whether this object has been passed through `rasterly_build`
is.rasterlyBuild(x)135 | 136 |
| x | 141 |a |
142 |
|---|