### Render High-Performance Scatter Plots with ggplot2 Source: https://context7.com/exaexa/scattermore/llms.txt Demonstrates using geom_scattermost for rendering millions of points efficiently by bypassing standard ggplot2 processing. Includes examples for both static coloring and density-based color mapping. ```r library(ggplot2) library(scattermore) # Maximum performance mode d <- data.frame(x = rnorm(1e6), y = rnorm(1e6)) x_rng <- range(d$x) ggplot() + geom_scattermost(xy = cbind(d$x, d$y), color = heat.colors(100, alpha = 0.01)[1 + 99 * (d$x - x_rng[1]) / diff(x_rng)], pointsize = 2.5, pixels = c(1000, 1000), interpolate = TRUE) + labs(title = "geom_scattermost: Maximum Performance") # Multi-colored points based on density n <- 2e6 xy <- cbind(rnorm(n), rnorm(n)) colors <- viridisLite::viridis(100, alpha = 0.05)[1 + floor(99 * pnorm(xy[, 2]))] ggplot() + geom_scattermost(xy = xy, color = colors, pointsize = 3, pixels = c(800, 800)) + coord_fixed() + theme_void() ``` -------------------------------- ### Render Line Segments to RGBWT Bitmap Source: https://context7.com/exaexa/scattermore/llms.txt Renders line segments defined by start and end coordinates into an RGBWT bitmap, suitable for visualizing networks or flow paths. ```r library(scattermore) n <- 5000 pts_start <- matrix(rnorm(n * 2), n, 2) pts_end <- cbind(pts_start[, 1] + rnorm(n, 2), pts_start[, 2] - rexp(n, 0.5)) lines_xy <- cbind(pts_start, pts_end) rgbwt_lines <- scatter_lines_rgbwt(xy = lines_xy, out_size = c(512, 512), RGBA = c(128, 16, 240, 5)) plot(rgba_int_to_raster(rgbwt_to_rgba_int(rgbwt_lines))) ``` -------------------------------- ### Create Multi-Layer Scatter Visualization Source: https://context7.com/exaexa/scattermore/llms.txt This script demonstrates the workflow for generating a multi-layered visualization. It includes creating a density background, rendering connecting lines, and plotting clustered points, which are then merged and converted to a raster image. ```R # Generate data pts_main <- cbind(rnorm(n), rnorm(n)) pts_secondary <- cbind(4 + rnorm(n/2, sd = 0.5), rnorm(n/2, sd = 2)) clusters <- kmeans(pts_main, 4)$cluster # Layer 1: Background density hist_bg <- scatter_points_histogram(pts_secondary, out_size = c(800, 800), xlim = c(-4, 6), ylim = c(-4, 4)) hist_bg <- apply_kernel_histogram(hist_bg, filter = "gauss", radius = 20) rgbwt_bg <- histogram_to_rgbwt(sqrt(hist_bg), col = gray.colors(50, 0.9, 0.3)) # Layer 2: Connecting lines rgbwt_lines <- scatter_lines_rgbwt(lines_data, out_size = c(800, 800), xlim = c(-4, 6), ylim = c(-4, 4), RGBA = c(200, 200, 100, 2)) # Layer 3: Main clustered points rgbwt_pts <- scatter_points_rgbwt(pts_main, out_size = c(800, 800), xlim = c(-4, 6), ylim = c(-4, 4), palette = palette, map = clusters) rgbwt_pts <- apply_kernel_rgbwt(rgbwt_pts, filter = "circle", radius = 4) # Merge and render rgbwt_merged <- merge_rgbwt(list(rgbwt_bg, rgbwt_lines, rgbwt_pts)) raster <- rgba_int_to_raster(rgbwt_to_rgba_int(rgbwt_merged)) ``` -------------------------------- ### Manual Rasterization with scattermore Source: https://github.com/exaexa/scattermore/blob/master/README.md Demonstrates the manual use of the scattermore function to generate raster graphics. This approach allows for custom processing or plotting of the resulting raster data. ```R data <- cbind(rnorm(1e7),rnorm(1e7)) par(mar=rep(0,4)) system.time(plot(scattermore(data, rgba=c(64,128,192,10), xlim=c(-3,3), ylim=c(-3,3)))) ``` -------------------------------- ### Create Line Density Histograms Source: https://context7.com/exaexa/scattermore/llms.txt Visualizes path densities or flow patterns by creating a density histogram from line segments using scatter_lines_histogram. ```r library(scattermore) # Generate random walk paths paths <- list() for (i in 1:1000) { x <- cumsum(rnorm(100, 0, 0.1)) y <- cumsum(rnorm(100, 0, 0.1)) paths[[i]] <- cbind(x[-100], y[-100], x[-1], y[-1]) } all_lines <- do.call(rbind, paths) line_hist <- scatter_lines_histogram(xy = all_lines, out_size = c(512, 512)) image(log1p(line_hist), col = viridisLite::magma(100)) ``` -------------------------------- ### Create Scatterplot with scattermoreplot Source: https://github.com/exaexa/scattermore/blob/master/README.md Demonstrates the basic usage of scattermoreplot to render a large number of points efficiently. It accepts standard plotting parameters similar to the base R plot function. ```R library(scattermore) scattermoreplot(rnorm(1e7), rnorm(1e7), col=heat.colors(1e7, alpha=.1), main='Scattermore demo') ``` -------------------------------- ### Create Point Density Histograms Source: https://context7.com/exaexa/scattermore/llms.txt Generates a 2D density map from point coordinates using scatter_points_histogram, returning an integer matrix of point counts per pixel. ```r library(scattermore) n <- 50000 pts <- rbind(cbind(rnorm(n/2, -1), rnorm(n/2, -1)), cbind(rnorm(n/2, 1), rnorm(n/2, 1))) hist2d <- scatter_points_histogram(xy = pts, out_size = c(256, 256), xlim = c(-4, 4), ylim = c(-4, 4)) image(hist2d, col = viridisLite::viridis(100)) image(log1p(hist2d), col = heat.colors(100)) ``` -------------------------------- ### Render Points to RGBWT Bitmap Source: https://context7.com/exaexa/scattermore/llms.txt Utilizes scatter_points_rgbwt to render points into a bitmap format that supports order-independent blending. Demonstrates single-color, multi-color, and indexed palette rendering. ```r library(scattermore) n <- 10000 pts <- matrix(rnorm(n * 2), n, 2) # Single color rgbwt <- scatter_points_rgbwt(xy = pts, out_size = c(512, 512), RGBA = c(0, 0, 255, 128)) plot(rgba_int_to_raster(rgbwt_to_rgba_int(rgbwt))) # Individual color per point colors <- col2rgb(rainbow(n, alpha = 0.3), alpha = TRUE) rgbwt_multi <- scatter_points_rgbwt(xy = pts, out_size = c(512, 512), RGBA = colors) plot(rgba_int_to_raster(rgbwt_to_rgba_int(rgbwt_multi))) # Indexed palette clusters <- 1 + (pts[, 1] < 0) + 2 * (pts[, 2] < 0) palette <- col2rgb(rainbow(4, alpha = 0.5), alpha = TRUE) rgbwt_indexed <- scatter_points_rgbwt(xy = pts, out_size = c(512, 512), palette = palette, map = clusters) plot(rgba_int_to_raster(rgbwt_to_rgba_int(rgbwt_indexed))) ``` -------------------------------- ### blend_rgba_float Source: https://context7.com/exaexa/scattermore/llms.txt Blends floating-point RGBA layers with standard alpha compositing. Layer order matters, with the first layer in the list appearing on top. ```APIDOC ## blend_rgba_float ### Description Blends floating-point RGBA layers with standard alpha compositing. Unlike merge_rgbwt(), layer order matters. ### Method Function Call ### Parameters #### Request Body - **layers** (list) - Required - A list of floating-point RGBA arrays. ### Response #### Success Response (200) - **rgba_blended** (array) - The resulting blended floating-point RGBA array. ``` -------------------------------- ### Blend RGBA Float Layers Source: https://context7.com/exaexa/scattermore/llms.txt Performs standard alpha compositing on floating-point RGBA layers. Unlike merge_rgbwt, the order of the list determines the visual stacking, where the first element is rendered on top. ```r rgba_blended <- blend_rgba_float(list(rgba_fg, rgba_bg)) raster <- rgba_int_to_raster(rgba_float_to_rgba_int(rgba_blended)) plot(raster) ``` -------------------------------- ### scatter_points_rgbwt Source: https://context7.com/exaexa/scattermore/llms.txt Renders colored points to a RGBWT bitmap. This format supports order-independent blending and is the foundation for advanced compositing operations. ```APIDOC ## scatter_points_rgbwt ### Description Renders colored points to a RGBWT (Red-Green-Blue-Weight-Transparency) bitmap. This format supports order-independent blending and is the foundation for advanced compositing operations. ### Method `scatter_points_rgbwt` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **xy** (matrix) - Required - A matrix where each row represents a point (x, y). - **out_size** (numeric vector) - Required - A vector of two integers specifying the width and height of the output bitmap. - **xlim** (numeric vector) - Optional - A vector of two numbers specifying the x-axis limits for mapping points to pixels. - **ylim** (numeric vector) - Optional - A vector of two numbers specifying the y-axis limits for mapping points to pixels. - **RGBA** (numeric vector or matrix) - Optional - Either a single vector of four integers (R, G, B, Alpha) for a uniform color, or a matrix where each row corresponds to a point's RGBA color. - **palette** (numeric matrix) - Optional - A matrix where each row is an RGB or RGBA color, used with the `map` parameter. - **map** (integer vector) - Optional - A vector of integer indices (1-based) into the `palette` for coloring points. - **skip_start_pixel** (logical) - Optional - Whether to skip rendering the starting pixel of a line segment (relevant for `scatter_lines_rgbwt`). - **skip_end_pixel** (logical) - Optional - Whether to skip rendering the ending pixel of a line segment (relevant for `scatter_lines_rgbwt`). ### Request Example ```r library(scattermore) # Generate test data n <- 10000 pts <- matrix(rnorm(n * 2), n, 2) # Single color for all points rgbwt <- scatter_points_rgbwt( xy = pts, out_size = c(512, 512), xlim = c(-3, 3), ylim = c(-3, 3), RGBA = c(0, 0, 255, 128) # Semi-transparent blue ) ``` ### Response #### Success Response (200) Returns a raw vector representing the RGBWT bitmap. #### Response Example ```r # To visualize the output, convert to a raster object rstr <- rgba_int_to_raster(rgbwt_to_rgba_int(rgbwt)) plot(rstr) ``` ``` -------------------------------- ### Integrate scattermore with ggplot2 Source: https://github.com/exaexa/scattermore/blob/master/README.md Shows how to use geom_scattermore or geom_scattermost within a ggplot2 workflow to rasterize graphics, which is useful for reducing PDF file sizes and improving rendering speed. ```R ggplot(....) + geom_scattermore() ``` -------------------------------- ### scatter_lines_rgbwt Source: https://context7.com/exaexa/scattermore/llms.txt Renders line segments to a RGBWT bitmap. Each row of input defines a line from (x1, y1) to (x2, y2). ```APIDOC ## scatter_lines_rgbwt ### Description Renders line segments to a RGBWT bitmap. Each row of input defines a line from (x1, y1) to (x2, y2). ### Method `scatter_lines_rgbwt` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **xy** (matrix) - Required - A matrix where each row represents a line segment with coordinates (x1, y1, x2, y2). - **out_size** (numeric vector) - Required - A vector of two integers specifying the width and height of the output bitmap. - **xlim** (numeric vector) - Optional - A vector of two numbers specifying the x-axis limits for mapping lines to pixels. - **ylim** (numeric vector) - Optional - A vector of two numbers specifying the y-axis limits for mapping lines to pixels. - **RGBA** (numeric vector or matrix) - Optional - Either a single vector of four integers (R, G, B, Alpha) for a uniform line color, or a matrix where each row corresponds to a line's RGBA color. - **skip_start_pixel** (logical) - Optional - Whether to skip rendering the starting pixel of a line segment. - **skip_end_pixel** (logical) - Optional - Whether to skip rendering the ending pixel of a line segment. ### Request Example ```r library(scattermore) # Create line data: each row is (x1, y1, x2, y2) n <- 5000 pts_start <- matrix(rnorm(n * 2), n, 2) pts_end <- cbind(pts_start[, 1] + rnorm(n, 2), pts_start[, 2] - rexp(n, 0.5)) lines_xy <- cbind(pts_start, pts_end) # Render lines with transparency rgbwt_lines <- scatter_lines_rgbwt( xy = lines_xy, out_size = c(512, 512), xlim = c(-3, 7), ylim = c(-5, 3), RGBA = c(128, 16, 240, 5), # Purple with low alpha skip_start_pixel = FALSE, skip_end_pixel = TRUE # Avoid double-counting for connected ribbons ) ``` ### Response #### Success Response (200) Returns a raw vector representing the RGBWT bitmap. #### Response Example ```r rstr <- rgba_int_to_raster(rgbwt_to_rgba_int(rgbwt_lines)) par(mar = c(0, 0, 0, 0)) plot(rstr) ``` ``` -------------------------------- ### scatter_lines_histogram Source: https://context7.com/exaexa/scattermore/llms.txt Creates a density histogram from line segments. Useful for visualizing path densities or flow patterns. ```APIDOC ## scatter_lines_histogram ### Description Creates a density histogram from line segments. Useful for visualizing path densities or flow patterns. ### Method `scatter_lines_histogram` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **xy** (matrix) - Required - A matrix where each row represents a line segment with coordinates (x1, y1, x2, y2). - **out_size** (numeric vector) - Required - A vector of two integers specifying the width and height of the output histogram grid. - **xlim** (numeric vector) - Optional - A vector of two numbers specifying the x-axis limits for mapping lines to histogram bins. - **ylim** (numeric vector) - Optional - A vector of two numbers specifying the y-axis limits for mapping lines to histogram bins. ### Request Example ```r library(scattermore) # Random walk paths n_paths <- 1000 path_length <- 100 paths <- list() for (i in 1:n_paths) { x <- cumsum(rnorm(path_length, 0, 0.1)) y <- cumsum(rnorm(path_length, 0, 0.1)) # Convert to line segments paths[[i]] <- cbind( x[-path_length], y[-path_length], x[-1], y[-1] ) } all_lines <- do.call(rbind, paths) # Create line density histogram line_hist <- scatter_lines_histogram( xy = all_lines, out_size = c(512, 512) ) ``` ### Response #### Success Response (200) Returns an integer matrix representing the 2D histogram of line densities. #### Response Example ```r # Visualize par(mar = c(0, 0, 2, 0)) image(log1p(line_hist), col = viridisLite::magma(100), main = "Random Walk Density") ``` ``` -------------------------------- ### scatter_points_histogram Source: https://context7.com/exaexa/scattermore/llms.txt Creates a 2D histogram (density map) from point coordinates. Returns an integer matrix where each cell contains the count of points falling into that pixel. ```APIDOC ## scatter_points_histogram ### Description Creates a 2D histogram (density map) from point coordinates. Returns an integer matrix where each cell contains the count of points falling into that pixel. ### Method `scatter_points_histogram` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **xy** (matrix) - Required - A matrix where each row represents a point (x, y). - **out_size** (numeric vector) - Required - A vector of two integers specifying the width and height of the output histogram grid. - **xlim** (numeric vector) - Optional - A vector of two numbers specifying the x-axis limits for mapping points to histogram bins. - **ylim** (numeric vector) - Optional - A vector of two numbers specifying the y-axis limits for mapping points to histogram bins. ### Request Example ```r library(scattermore) # Generate clustered data n <- 50000 pts <- rbind( cbind(rnorm(n/2, -1), rnorm(n/2, -1)), cbind(rnorm(n/2, 1), rnorm(n/2, 1)) ) # Create histogram hist2d <- scatter_points_histogram( xy = pts, out_size = c(256, 256), xlim = c(-4, 4), ylim = c(-4, 4) ) ``` ### Response #### Success Response (200) Returns an integer matrix representing the 2D histogram. #### Response Example ```r # Visualize with image() par(mar = c(0, 0, 2, 0)) image(hist2d, col = viridisLite::viridis(100), main = "Point Density") # Apply log transform for better visualization of varying densities image(log1p(hist2d), col = heat.colors(100), main = "Log Density") ``` ``` -------------------------------- ### Apply Kernel to RGBWT Data (R) Source: https://context7.com/exaexa/scattermore/llms.txt Applies a convolution kernel to expand single-pixel points or lines in RGBWT format. Supports predefined kernels like 'circle', 'square', and 'gauss', as well as custom kernels defined by a mask. This function is useful for creating thicker lines or larger points from sparse data. ```r library(scattermore) # Create point data pts <- matrix(rnorm(2000), 1000, 2) clusters <- 1 + (pts[, 1] > 0) palette <- col2rgb(c("#E41A1C80", "#377EB880"), alpha = TRUE) # Render as single pixels rgbwt <- scatter_points_rgbwt( xy = pts, out_size = c(512, 512), palette = palette, map = clusters ) # Expand with circular kernel rgbwt_circle <- apply_kernel_rgbwt( fRGBWT = rgbwt, filter = "circle", radius = 8 ) plot(rgba_int_to_raster(rgbwt_to_rgba_int(rgbwt_circle))) # Gaussian blur for soft edges rgbwt_gauss <- apply_kernel_rgbwt( fRGBWT = rgbwt, filter = "gauss", radius = 10, sigma = 4 ) plot(rgba_int_to_raster(rgbwt_to_rgba_int(rgbwt_gauss))) # Custom kernel for special effects custom_kernel <- outer(1:11, 1:11, function(x, y) { 1 / (1 + abs(x - 6) + abs(y - 6)) }) rgbwt_custom <- apply_kernel_rgbwt( fRGBWT = rgbwt, mask = custom_kernel ) plot(rgba_int_to_raster(rgbwt_to_rgba_int(rgbwt_custom))) # Apply to lines for thicker strokes lines_xy <- cbind(pts[1:100, ], pts[101:200, ]) rgbwt_lines <- scatter_lines_rgbwt(lines_xy, out_size = c(512, 512), RGBA = c(0, 100, 200, 30)) rgbwt_thick <- apply_kernel_rgbwt(rgbwt_lines, filter = "circle", radius = 3) plot(rgba_int_to_raster(rgbwt_to_rgba_int(rgbwt_thick))) ``` -------------------------------- ### Convert RGBWT to Float RGBA (R) Source: https://context7.com/exaexa/scattermore/llms.txt Converts RGBWT data to floating-point RGBA format with premultiplied alpha. This format is specifically required for alpha-blending operations using functions like `blend_rgba_float()`, allowing for seamless compositing of multiple layers. ```r library(scattermore) # Create two overlapping layers pts1 <- cbind(rnorm(5000, -1), rnorm(5000)) pts2 <- cbind(rnorm(5000, 1), rnorm(5000)) rgbwt1 <- scatter_points_rgbwt(pts1, out_size = c(512, 512), RGBA = c(255, 0, 0, 150)) rgbwt2 <- scatter_points_rgbwt(pts2, out_size = c(512, 512), RGBA = c(0, 0, 255, 150)) ``` -------------------------------- ### Compare geom_point and geom_scattermost in R Source: https://github.com/exaexa/scattermore/blob/master/README.md This snippet demonstrates how to generate a large scatterplot using standard ggplot2 geom_point versus the scattermore geom_scattermost function. It highlights the difference in rendering approach and color mixing precision for high-density datasets. ```r library(ggplot2) library(scattermore) # data d <- cbind(rnorm(1e6),runif(1e6)) # first plot (geom_point) ggsave('point.png', units='in', width=3, height=3, ggplot(data.frame(x=d[,1],y=d[,2])) + geom_point(shape='.', alpha=.05, aes(x,y,color=y)) + scale_color_viridis_c(guide='none') + ggtitle("geom_point")) # second plot (geom_scattermost) ggsave('scattermore.png', units='in', width=3, height=3, ggplot() + geom_scattermost( d, col=viridisLite::viridis(100, alpha=0.05)[1+99*d[,2]], pointsize=2, pixels=c(700,700)) + ggtitle("geom_scattermost")) ``` -------------------------------- ### Convert RGBA Float to Integer Source: https://context7.com/exaexa/scattermore/llms.txt Converts premultiplied floating-point RGBA data to non-premultiplied integer RGBA format. This is typically performed after blending operations to prepare data for raster conversion or PNG export. ```r library(scattermore) pts <- matrix(rnorm(10000), 5000, 2) rgbwt <- scatter_points_rgbwt(pts, out_size = c(512, 512)) rgbwt <- apply_kernel_rgbwt(rgbwt, radius = 3) rgba_float <- rgbwt_to_rgba_float(rgbwt) rgba_int <- rgba_float_to_rgba_int(rgba_float) raster <- rgba_int_to_raster(rgba_int) plot(raster) ``` -------------------------------- ### Convert RGBWT to Integer RGBA (R) Source: https://context7.com/exaexa/scattermore/llms.txt Converts data from the RGBWT format to an integer RGBA format, where each channel (Red, Green, Blue, Alpha) ranges from 0 to 255. The output is not premultiplied by alpha. This is a common intermediate step for displaying or further processing raster data. ```r library(scattermore) # Create RGBWT data pts <- matrix(rnorm(10000), 5000, 2) rgbwt <- scatter_points_rgbwt(pts, out_size = c(512, 512), RGBA = c(255, 128, 0, 100)) # Convert to integer RGBA rgba_int <- rgbwt_to_rgba_int(rgbwt) # Inspect structure dim(rgba_int) # [1] 512 512 4 (height x width x RGBA channels) range(rgba_int) # Values 0-255 # Convert to R raster and plot raster <- rgba_int_to_raster(rgba_int) plot(raster) ``` -------------------------------- ### rgba_float_to_rgba_int Source: https://context7.com/exaexa/scattermore/llms.txt Converts floating-point RGBA (premultiplied) to integer RGBA (non-premultiplied). Used after blend_rgba_float() operations to prepare data for raster conversion. ```APIDOC ## rgba_float_to_rgba_int ### Description Converts floating-point RGBA (premultiplied) to integer RGBA (non-premultiplied). Used after blend_rgba_float() operations. ### Method Function Call ### Parameters #### Request Body - **rgba_float** (array) - Required - Floating-point RGBA array (premultiplied). ### Response #### Success Response (200) - **rgba_int** (array) - Integer RGBA array (non-premultiplied). ``` -------------------------------- ### Apply Kernel to Histogram Data (R) Source: https://context7.com/exaexa/scattermore/llms.txt Applies a convolution kernel to smooth or expand histogram data. This function is commonly used for density estimation and creating smooth heatmaps from point data. It supports predefined kernels and parameters like radius and sigma for Gaussian blurs. ```r library(scattermore) # Create bimodal point distribution pts <- rbind( cbind(rnorm(5000, -2), rnorm(5000, -2)), cbind(rnorm(5000, 2), rnorm(5000, 2)) ) # Raw histogram hist2d <- scatter_points_histogram( xy = pts, out_size = c(256, 256), xlim = c(-5, 5), ylim = c(-5, 5) ) # Gaussian smoothing for density estimation hist_smooth <- apply_kernel_histogram( fhistogram = hist2d, filter = "gauss", radius = 15, sigma = 5 ) par(mfrow = c(1, 2), mar = c(0, 0, 2, 0)) image(hist2d, col = viridisLite::viridis(100), main = "Raw Histogram") image(hist_smooth, col = viridisLite::viridis(100), main = "Gaussian Smoothed") # Create contour overlay par(mfrow = c(1, 1)) image(hist_smooth, col = topo.colors(100)[20:100]) contour(hist_smooth, levels = c(5, 15, 30, 50), add = TRUE, col = "white") # Square kernel for blocky effect hist_square <- apply_kernel_histogram(hist2d, filter = "square", radius = 5) image(hist_square, col = heat.colors(100)) ``` -------------------------------- ### Convert Histogram to RGBWT Raster (R) Source: https://context7.com/exaexa/scattermore/llms.txt Converts a numeric histogram to a colorized RGBWT raster using a specified color palette. This is essential for creating colored density visualizations that can be composited with other graphical layers. Supports custom color palettes and control over the value range mapped to colors. ```r library(scattermore) # Create density data pts <- cbind(rnorm(20000), rexp(20000)) hist2d <- scatter_points_histogram(pts, out_size = c(512, 512)) hist_smooth <- apply_kernel_histogram(hist2d, filter = "gauss", radius = 10) # Colorize with default palette rgbwt <- histogram_to_rgbwt(log1p(hist_smooth)) plot(rgba_int_to_raster(rgbwt_to_rgba_int(rgbwt))) # Custom color palette custom_colors <- colorRampPalette(c("darkblue", "cyan", "yellow", "red"))(100) rgbwt_custom <- histogram_to_rgbwt( fhistogram = log1p(hist_smooth), col = custom_colors, zlim = c(0, max(log1p(hist_smooth))) # Control value range ) plot(rgba_int_to_raster(rgbwt_to_rgba_int(rgbwt_custom))) # Using topo.colors for terrain-like visualization rgbwt_topo <- histogram_to_rgbwt( fhistogram = sqrt(hist_smooth), RGBA = col2rgb(topo.colors(50)[10:50], alpha = TRUE) ) plot(rgba_int_to_raster(rgbwt_to_rgba_int(rgbwt_topo))) ``` -------------------------------- ### rgbwt_to_rgba_int Source: https://context7.com/exaexa/scattermore/llms.txt Converts RGBWT format to integer RGBA (0-255 per channel), suitable for display or raster conversion. ```APIDOC ## FUNCTION rgbwt_to_rgba_int ### Description Converts RGBWT format to integer RGBA (0-255 per channel). Output is not premultiplied by alpha. ### Parameters #### Arguments - **rgbwt** (matrix) - Required - The input RGBWT matrix. ### Request Example rgba_int <- rgbwt_to_rgba_int(rgbwt) ### Response - **output** (array) - An array of dimensions [height, width, 4] with integer values 0-255. ``` -------------------------------- ### Convert RGBA Integer to Raster Source: https://context7.com/exaexa/scattermore/llms.txt Converts an integer RGBA array into an R raster object. This allows for rendering point cloud data using base R graphics or precise positioning with rasterImage. ```r pts <- cbind(rnorm(50000), rnorm(50000)) rgbwt <- scatter_points_rgbwt(pts, out_size = c(800, 800), RGBA = c(100, 50, 200, 30)) rgbwt <- apply_kernel_rgbwt(rgbwt, filter = "gauss", radius = 5) rgba_int <- rgbwt_to_rgba_int(rgbwt) raster <- rgba_int_to_raster(rgba_int) plot(raster, interpolate = FALSE) ``` -------------------------------- ### Integrate Scatterplots with ggplot2 using geom_scattermore Source: https://context7.com/exaexa/scattermore/llms.txt A ggplot2 geometry that renders scatterplots as rasters. This allows for standard ggplot2 aesthetics and theme usage while maintaining small file sizes for exported documents. ```r library(ggplot2) library(scattermore) df <- data.frame(x = rnorm(1e6), y = rexp(1e6)) ggplot(df) + geom_scattermore(aes(x = x, y = y, color = x), pointsize = 3, alpha = 0.1, pixels = c(1000, 1000), interpolate = TRUE) + scale_color_viridis_c() + theme_minimal() df1 <- data.frame(x = rnorm(5e5, 0), y = rnorm(5e5, 0), group = "A") df2 <- data.frame(x = rnorm(5e5, 3), y = rnorm(5e5, 3), group = "B") df <- rbind(df1, df2) ggplot(df) + geom_scattermore(aes(x = x, y = y, color = group), pointsize = 2, alpha = 0.3, pixels = c(800, 800)) + scale_color_manual(values = c("A" = "#E41A1C", "B" = "#377EB8")) ``` -------------------------------- ### apply_kernel_rgbwt Source: https://context7.com/exaexa/scattermore/llms.txt Applies a convolution kernel to expand single-pixel points or lines in RGBWT format, supporting predefined kernels like circle, square, or gauss, as well as custom masks. ```APIDOC ## FUNCTION apply_kernel_rgbwt ### Description Applies a convolution kernel to expand single-pixel points or lines in RGBWT format. Supports predefined kernels (circle, square, gauss) or custom kernels. ### Parameters #### Arguments - **fRGBWT** (matrix) - Required - The RGBWT input matrix. - **filter** (string) - Optional - The type of filter to apply: 'circle', 'square', or 'gauss'. - **radius** (numeric) - Optional - The radius of the kernel. - **sigma** (numeric) - Optional - The standard deviation for the Gaussian kernel. - **mask** (matrix) - Optional - A custom kernel matrix. ### Request Example rgbwt_circle <- apply_kernel_rgbwt(fRGBWT = rgbwt, filter = "circle", radius = 8) ### Response - **output** (matrix) - The processed RGBWT matrix. ``` -------------------------------- ### histogram_to_rgbwt Source: https://context7.com/exaexa/scattermore/llms.txt Converts a numeric histogram to a colorized RGBWT raster using a color palette, essential for creating colored density visualizations. ```APIDOC ## FUNCTION histogram_to_rgbwt ### Description Converts a numeric histogram to a colorized RGBWT raster using a color palette. ### Parameters #### Arguments - **fhistogram** (matrix) - Required - The input histogram matrix. - **col** (vector) - Optional - A color palette. - **zlim** (vector) - Optional - The range of values to map. ### Request Example rgbwt <- histogram_to_rgbwt(log1p(hist_smooth)) ### Response - **output** (matrix) - The resulting RGBWT raster. ``` -------------------------------- ### rgba_int_to_raster Source: https://context7.com/exaexa/scattermore/llms.txt Converts an integer RGBA array to an R raster object for plotting with base graphics. ```APIDOC ## rgba_int_to_raster ### Description Converts integer RGBA array to an R raster object for plotting with base graphics. ### Method Function Call ### Parameters #### Request Body - **rgba_int** (array) - Required - Integer RGBA array. ### Response #### Success Response (200) - **raster** (raster) - R raster object. ``` -------------------------------- ### Generate Rasterized Scatterplots with scattermore Source: https://context7.com/exaexa/scattermore/llms.txt The core scattermore function converts coordinate data into a rasterized image. It supports returning an R raster object for immediate plotting or a raw RGBA array for external image export. ```r library(scattermore) data <- cbind(rnorm(1e7), rnorm(1e7)) raster_img <- scattermore(xy = data, size = c(512, 512), xlim = c(-3, 3), ylim = c(-3, 3), rgba = c(64, 128, 192, 10), cex = 0, output.raster = TRUE) plot(raster_img) raster_large <- scattermore(xy = data[1:100000, ], size = c(800, 800), rgba = c(255, 100, 50, 100), cex = 3, output.raster = TRUE) plot(raster_large) raw_array <- scattermore(xy = data, size = c(1024, 1024), rgba = c(0, 0, 0, 20), output.raster = FALSE) ``` -------------------------------- ### merge_rgbwt Source: https://context7.com/exaexa/scattermore/llms.txt Merges multiple RGBWT layers using order-independent blending. Colors are mixed based on accumulated ink weight, eliminating overplotting artifacts. ```APIDOC ## merge_rgbwt ### Description Merges multiple RGBWT layers using order-independent blending. Colors are mixed based on accumulated 'ink weight' rather than layer order. ### Method Function Call ### Parameters #### Request Body - **layers** (list) - Required - A list of RGBWT layer objects. ### Response #### Success Response (200) - **rgbwt_merged** (object) - A single merged RGBWT layer. ``` -------------------------------- ### apply_kernel_histogram Source: https://context7.com/exaexa/scattermore/llms.txt Applies a convolution kernel to smooth or expand histogram data, commonly used for density estimation and creating smooth heatmaps. ```APIDOC ## FUNCTION apply_kernel_histogram ### Description Applies a convolution kernel to smooth or expand histogram data. Commonly used for density estimation and creating smooth heatmaps. ### Parameters #### Arguments - **fhistogram** (matrix) - Required - The input histogram matrix. - **filter** (string) - Optional - The type of filter: 'gauss' or 'square'. - **radius** (numeric) - Optional - The radius of the kernel. - **sigma** (numeric) - Optional - The standard deviation for the Gaussian kernel. ### Request Example hist_smooth <- apply_kernel_histogram(fhistogram = hist2d, filter = "gauss", radius = 15, sigma = 5) ### Response - **output** (matrix) - The smoothed histogram matrix. ``` -------------------------------- ### Merge RGBWT Layers Source: https://context7.com/exaexa/scattermore/llms.txt Merges multiple RGBWT layers using order-independent blending. This approach mixes colors based on accumulated ink weight, which is useful for avoiding overplotting artifacts in complex visualizations. ```r rgbwt_merged <- merge_rgbwt(list(rgbwt_points, rgbwt_lines)) plot(rgba_int_to_raster(rgbwt_to_rgba_int(rgbwt_merged))) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.