Skip to content

Commit

Permalink
version 0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
exaexa authored and cran-robot committed Nov 24, 2020
1 parent 9f8f277 commit 6f080bb
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 40 deletions.
10 changes: 5 additions & 5 deletions DESCRIPTION
@@ -1,6 +1,6 @@
Package: scattermore
Title: Scatterplots with More Points
Version: 0.6
Version: 0.7
Authors@R:
person(given = "Mirek",
family = "Kratochvil",
Expand All @@ -10,14 +10,14 @@ Authors@R:
Description: C-based conversion of large scatterplot data to rasters. Speeds up
plotting of data with millions of points.
URL: https://github.com/exaexa/scattermore
Imports: ggplot2
Imports: ggplot2, scales, grid, grDevices, graphics
License: GPL (>= 3)
Encoding: UTF-8
LazyData: true
RoxygenNote: 6.1.1
RoxygenNote: 7.1.1
NeedsCompilation: yes
Packaged: 2020-02-08 12:48:57 UTC; exa
Packaged: 2020-11-24 15:54:51 UTC; exa
Author: Mirek Kratochvil [aut, cre] (<https://orcid.org/0000-0001-7356-4075>)
Maintainer: Mirek Kratochvil <exa.exa@gmail.com>
Repository: CRAN
Date/Publication: 2020-03-06 16:00:02 UTC
Date/Publication: 2020-11-24 16:30:02 UTC
16 changes: 8 additions & 8 deletions MD5
@@ -1,8 +1,8 @@
d81fd4905c5bd314aff79f4f655498ea *DESCRIPTION
37c40e6e981eb27503ea428fc7fdbbb7 *NAMESPACE
557062a5504aa41d85f9058e52338916 *R/scattermore.R
4df13947cbda20ec22fe415b9a4947d2 *man/geom_scattermore.Rd
e5d7902d3950f1ffd767b95df868d7df *man/geom_scattermost.Rd
34795186242675fa4d59f5a26cb1d7a1 *man/scattermore.Rd
e0b9090ddfe05e75b24131c172e17662 *man/scattermoreplot.Rd
5e7acb2cf396cc3e2c3c76b62f3de16e *src/scattermore.c
a5b3661a4e9f8bbe0d3707109c7c84f3 *DESCRIPTION
77576a692dd14aa00bb71e0ba4fa764a *NAMESPACE
91b9629d94d82844cf99938fb5ea5895 *R/scattermore.R
637f342bff5d6a5defea59a293153625 *man/geom_scattermore.Rd
5b78e6854fb7cb8a3c4d50bed313f83c *man/geom_scattermost.Rd
9970bb95b4673867122ccd8eec489d4d *man/scattermore.Rd
f08e3e4232fe070b07b9c95453e9a1bd *man/scattermoreplot.Rd
ceaff950dec3433077397ac276f46bd6 *src/scattermore.c
15 changes: 15 additions & 0 deletions NAMESPACE
Expand Up @@ -4,4 +4,19 @@ export(geom_scattermore)
export(geom_scattermost)
export(scattermore)
export(scattermoreplot)
importFrom(ggplot2,Geom)
importFrom(ggplot2,aes)
importFrom(ggplot2,aes_string)
importFrom(ggplot2,draw_key_point)
importFrom(ggplot2,ggproto)
importFrom(ggplot2,layer)
importFrom(grDevices,as.raster)
importFrom(grDevices,col2rgb)
importFrom(grDevices,dev.size)
importFrom(grDevices,rgb)
importFrom(graphics,par)
importFrom(graphics,plot)
importFrom(graphics,rasterImage)
importFrom(grid,rasterGrob)
importFrom(scales,alpha)
useDynLib(scattermore, .registration = TRUE)
39 changes: 30 additions & 9 deletions R/scattermore.R
Expand Up @@ -41,6 +41,7 @@
#' library(scattermore)
#' plot(scattermore(cbind(rnorm(1e7),rnorm(1e7)), rgba=c(64,128,192,10)))
#' @export
#' @importFrom grDevices as.raster
scattermore <- function(
xy,
size=c(512,512),
Expand Down Expand Up @@ -81,6 +82,7 @@ scattermore <- function(
#' @param x,y,xlim,ylim,xlab,ylab,... used as in [graphics::plot()] or forwarded to [graphics::plot()]
#' @param col point color(s)
#' @param cex forwarded to [scattermore()]
#' @param pch ignored (to improve compatibility with [graphics::plot()]
#' @param size forwarded to [scattermore()], or auto-derived from device and plot size if missing (the estimate is not pixel-perfect on most devices, but gets pretty close)
#' @examples
#' # plot an actual rainbow
Expand All @@ -92,12 +94,18 @@ scattermore <- function(
#' col=rainbow(1e7, alpha=.01)[c((9e6+1):1e7, 1:9e6)],
#' main="scattermore demo")
#' @export
#' @importFrom graphics par
#' @importFrom graphics plot
#' @importFrom graphics rasterImage
#' @importFrom grDevices dev.size
#' @importFrom grDevices rgb
scattermoreplot <- function(
x, y,
xlim, ylim,
size,
col=grDevices::rgb(0,0,0,1),
cex=0,
pch=NULL,
xlab, ylab,
...)
{
Expand Down Expand Up @@ -130,12 +138,6 @@ scattermoreplot <- function(
)
}

# Internally used ggplot2 utility for naming grobs
ggname <- function(p, g) {
g$name <- grid::grobName(g, p)
g
}

#' geom_scattermore
#'
#' [ggplot2::ggplot()] integration. This cooperates with the rest of ggplot
Expand Down Expand Up @@ -164,6 +166,7 @@ ggname <- function(p, g) {
#' interpolate=TRUE) +
#' scale_color_viridis_c()
#' @export
#' @importFrom ggplot2 layer
geom_scattermore <- function(
mapping=NULL, data=NULL, stat="identity", position="identity", ...,
na.rm=FALSE, show.legend = NA, inherit.aes = TRUE,
Expand All @@ -187,6 +190,15 @@ geom_scattermore <- function(
)
}

#' The actual geom for scattermore
#'
#' @importFrom ggplot2 aes
#' @importFrom ggplot2 draw_key_point
#' @importFrom ggplot2 Geom
#' @importFrom ggplot2 ggproto
#' @importFrom grDevices col2rgb
#' @importFrom grid rasterGrob
#' @importFrom scales alpha
GeomScattermore <- ggplot2::ggproto("GeomScattermore", ggplot2::Geom,
required_aes = c("x", "y"),
non_missing_aes = c("alpha", "colour"),
Expand All @@ -200,11 +212,11 @@ GeomScattermore <- ggplot2::ggproto("GeomScattermore", ggplot2::Geom,
na.rm = FALSE, pixels=c(512,512)) {
coords <- coord$transform(data, pp)

ggname("geom_scattermore",
ggplot2:::ggname("geom_scattermore",
grid::rasterGrob(
scattermore(
cbind(coords$x, coords$y),
rgba=grDevices::col2rgb(alpha=TRUE, alpha(coords$colour, coords$alpha)),
rgba=grDevices::col2rgb(alpha=TRUE, scales::alpha(coords$colour, coords$alpha)),
cex=pointsize,
xlim=c(0,1),
ylim=c(0,1),
Expand Down Expand Up @@ -246,6 +258,8 @@ GeomScattermore <- ggplot2::ggproto("GeomScattermore", ggplot2::Geom,
#' pixels=c(1000,1000),
#' interpolate=TRUE)
#' @export
#' @importFrom ggplot2 aes_string
#' @importFrom ggplot2 layer
geom_scattermost <- function(
xy,
color = "black",
Expand All @@ -272,6 +286,13 @@ geom_scattermost <- function(
)
}

#' The actual geom for scattermost
#'
#' @importFrom ggplot2 draw_key_point
#' @importFrom ggplot2 Geom
#' @importFrom ggplot2 ggproto
#' @importFrom grDevices col2rgb
#' @importFrom grid rasterGrob
GeomScattermost <- ggplot2::ggproto("GeomScattermost", ggplot2::Geom,
required_aes = c("x", "y"),

Expand All @@ -283,7 +304,7 @@ GeomScattermost <- ggplot2::ggproto("GeomScattermost", ggplot2::Geom,
pixels=c(512,512)) {
coords <- coord$transform(data.frame(x=xy[,1],y=xy[,2]),pp)

ggname("geom_scattermost",
ggplot2:::ggname("geom_scattermost",
grid::rasterGrob(
scattermore(cbind(coords$x, coords$y),
cex=pointsize,
Expand Down
19 changes: 14 additions & 5 deletions man/geom_scattermore.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions man/geom_scattermost.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions man/scattermore.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 16 additions & 3 deletions man/scattermoreplot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/scattermore.c
Expand Up @@ -102,12 +102,12 @@ scattermore(const int *pn,
#define paint_circle \
const int cx = (xy[i] - xb) * xips, cy = (xy[i + n] - yb) * yips, \
pxb = cx <= cr ? 0 : cx - cr, \
pxe = cx + cr + 1 >= sizex ? sizex : cx + cr + 1, \
pxe = cx + cr + 1 >= (int)sizex ? (int)sizex : cx + cr + 1, \
pyb = cy <= cr ? 0 : cy - cr, \
pye = cy + cr + 1 >= sizey ? sizey : cy + cr + 1; \
pye = cy + cr + 1 >= (int)sizey ? (int)sizey : cy + cr + 1; \
\
for (size_t x = pxb; x < pxe; ++x) \
for (size_t y = pyb; y < pye; ++y) { \
for (int x = pxb; x < pxe; ++x) \
for (int y = pyb; y < pye; ++y) { \
int tmp = (x - cx) * (x - cx) + (y - cy) * (y - cy); \
if (tmp > crsq1) \
continue; \
Expand Down

0 comments on commit 6f080bb

Please sign in to comment.