Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 0.2.0 #19

Merged
merged 45 commits into from
Sep 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
f66cdbc
README mistake, geom_quasirandom_rast
evanbiederstedt Jul 6, 2020
85a03c1
Add rasterise() function
teunbrand Jul 7, 2020
bbb6a0f
Add grid to imports, ragg/png to suggests
teunbrand Jul 7, 2020
65b2731
Move ragg & png to imports
teunbrand Jul 7, 2020
8e03af4
Drop ragg/png presence checks
teunbrand Jul 7, 2020
813c979
Merge pull request #17 from teunbrand/master
VPetukhov Jul 20, 2020
69a5dd8
add authorship
evanbiederstedt Aug 17, 2020
f7385de
add Teun to contributors
evanbiederstedt Aug 17, 2020
a71e9c3
update README
evanbiederstedt Aug 18, 2020
5321f03
update README
evanbiederstedt Aug 18, 2020
b8ea08e
update wrapper functions
evanbiederstedt Aug 18, 2020
cc29a43
update vignettes, remove raster.width
evanbiederstedt Aug 18, 2020
eade99e
update documentation
evanbiederstedt Aug 18, 2020
3624579
revise DESCRIPTION, README
evanbiederstedt Aug 18, 2020
428bfdb
update version
evanbiederstedt Aug 18, 2020
b815ff5
update version
evanbiederstedt Aug 18, 2020
c754b5e
add geom_violin_rast
evanbiederstedt Aug 18, 2020
620c6ed
update params, documentation
evanbiederstedt Aug 18, 2020
8f88360
revert back to original geom_boxplot_jitter code
evanbiederstedt Aug 18, 2020
66f01f7
reinsert default values in ggbeeswarm plots
evanbiederstedt Aug 18, 2020
f15210e
update vignettes
evanbiederstedt Aug 21, 2020
d25642f
correct name, vignettes
evanbiederstedt Aug 21, 2020
e416f60
corrections for CRAN
evanbiederstedt Aug 22, 2020
c00452d
update /doc files
evanbiederstedt Aug 22, 2020
626675e
update /doc
evanbiederstedt Aug 22, 2020
1870808
revise .gitignore; allow doc, Meta
evanbiederstedt Aug 22, 2020
8048361
update vignettes, doc figure sizes
evanbiederstedt Aug 22, 2020
4639481
revise .gitignore
evanbiederstedt Aug 25, 2020
211db0e
update CHANGELOG
evanbiederstedt Sep 4, 2020
0465924
update CHANGELOG
evanbiederstedt Sep 4, 2020
b1b6b97
updated README
evanbiederstedt Sep 8, 2020
b820acb
readme update
evanbiederstedt Sep 8, 2020
7993f23
Merge pull request #18 from VPetukhov/feature/rasterizer
evanbiederstedt Sep 11, 2020
27cc53e
update CHANGELOG
evanbiederstedt Sep 11, 2020
3a250f9
update vignettes
evanbiederstedt Sep 11, 2020
aa28537
use https
evanbiederstedt Sep 11, 2020
f8701eb
update vignettes, README
evanbiederstedt Sep 11, 2020
a02b88b
revise figure sizes
evanbiederstedt Sep 11, 2020
8b2f71b
use "rasteriser"
evanbiederstedt Sep 11, 2020
d4f9aa5
updated vignettes
evanbiederstedt Sep 11, 2020
d95ba73
update, revise vignettes
evanbiederstedt Sep 11, 2020
d1dcc6c
update vignettes
evanbiederstedt Sep 11, 2020
3316ab0
remove .DS_Store
evanbiederstedt Sep 11, 2020
8252f78
fix geom_boxplot_jitter
evanbiederstedt Sep 12, 2020
52d2521
update docs
evanbiederstedt Sep 12, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
.Rproj.user
.Rhistory
.RData
.Ruserdata
ggrastr*.tar.gz
doc
Meta
.Rproj.user
.Rhistory
.RData
.Ruserdata
ggrastr*.tar.gz
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [0.2.0] - 2020-08
* Refactor code to use rasterise()
* Added `geom_violin_rast()` as a feature request
* Updated vignettes accordingly
* Updated README

## [0.1.9] - 2020-06-19
* Added geom-jitter-rast
* Revised vignettes to detail all functions
Expand Down
53 changes: 28 additions & 25 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
Package: ggrastr
Type: Package
Title: Raster Layers for 'ggplot2'
Version: 0.1.9
Authors@R: c(person("Viktor", "Petukhov", email = "viktor.s.petukhov@ya.ru", role = c("aut", "cph")), person("Evan", "Biederstedt", email = "evan.biederstedt@gmail.com", role=c("cre", "aut")))
Description: Provides a set of geoms to rasterize only specific layers of the plot while simultaneously keeping all labels and text in vector format. This allows users to keep plots within the reasonable size limit without loosing vector properties of the scale-sensitive information.
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
Imports:
ggplot2 (>= 2.1.0),
Cairo (>= 1.5.9),
ggbeeswarm
Depends:
R (>= 3.2.2)
RoxygenNote: 7.1.1
Suggests:
rmarkdown,
knitr
VignetteBuilder: knitr
URL: https://github.com/VPetukhov/ggrastr
BugReports: https://github.com/VPetukhov/ggrastr/issues
NeedsCompilation: no
Author: Viktor Petukhov [aut, cph], Evan Biederstedt [cre, aut]
Maintainer: Evan Biederstedt <evan.biederstedt@gmail.com>
Package: ggrastr
Type: Package
Title: Raster Layers for 'ggplot2'
Version: 0.2.0
Authors@R: c(person("Viktor", "Petukhov", email = "viktor.s.petukhov@ya.ru", role = c("aut", "cph")), person("Teun", "van den Brand", email = "t.vd.brand@nki.nl", role=c("aut")), person("Evan", "Biederstedt", email = "evan.biederstedt@gmail.com", role=c("cre", "aut")))
Description: Provides a set of geoms to rasterize only specific layers of the plot while simultaneously keeping all labels and text in vector format. This allows users to keep plots within the reasonable size limit without loosing vector properties of the scale-sensitive information.
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
Imports:
ggplot2 (>= 2.1.0),
Cairo (>= 1.5.9),
ggbeeswarm,
grid,
ragg,
png
Depends:
R (>= 3.2.2)
RoxygenNote: 7.1.1
Suggests:
rmarkdown,
knitr
VignetteBuilder: knitr
URL: https://github.com/VPetukhov/ggrastr
BugReports: https://github.com/VPetukhov/ggrastr/issues
NeedsCompilation: no
Author: Viktor Petukhov [aut, cph], Teun van den Brand [aut], Evan Biederstedt [cre, aut]
Maintainer: Evan Biederstedt <evan.biederstedt@gmail.com>
9 changes: 5 additions & 4 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# Generated by roxygen2: do not edit by hand

S3method(makeContext,rasteriser)
export(geom_beeswarm_rast)
export(geom_boxplot_jitter)
export(geom_jitter_rast)
export(geom_point_rast)
export(geom_quasirandom_rast)
export(geom_tile_rast)
export(geom_violin_rast)
export(rasterise)
export(rasterize)
export(theme_pdf)
import(ggbeeswarm)
import(ggplot2)
importFrom(grDevices,dev.cur)
importFrom(grDevices,dev.off)
importFrom(grDevices,dev.set)
importFrom(graphics,par)
importFrom(grid,makeContext)
38 changes: 5 additions & 33 deletions R/geom-beeswarm-rast.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#' @param cex Scaling for adjusting point spacing (see ggbeeswarm::position_beeswarm)
#' @param groupOnX Should jitter be added to the x axis if TRUE or y axis if FALSE (the default NULL causes the function to guess which axis is the categorical one based on the number of unique entries in each) Refer to see ggbeeswarm::position_beeswarm
#' @param dodge.width Amount by which points from different aesthetic groups will be dodged. This requires that one of the aesthetics is a factor. (see ggbeeswarm::position_beeswarm)
#' @param raster.dpi An integer of length one setting the desired resolution in dots per inch. (default=NULL)
#' @param dev A character specifying a device. Can be one of: \code{"cairo"}, \code{"ragg"} or \code{"ragg_png"}. (default="cairo")
#' @return geom_beeswarm plot with rasterized layer
#'
#' @examples
Expand All @@ -17,37 +19,7 @@
#' ggplot(mtcars) + geom_beeswarm_rast(aes(x = factor(cyl), y = mpg), raster.dpi = 600, cex = 1.5)
#'
#' @export
geom_beeswarm_rast <- function(
mapping = NULL,
data = NULL,
stat = 'identity',
position = 'quasirandom',
priority = c('ascending', 'descending', 'density', 'random', 'none'),
cex = 1,
groupOnX = NULL,
dodge.width = 0,
...,
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE,
raster.width = NULL, raster.height = NULL, raster.dpi = 300
) {

position <- ggbeeswarm::position_beeswarm(priority = priority, cex = cex,
groupOnX = groupOnX, dodge.width = dodge.width)

ggplot2::layer(
data = data,
mapping = mapping,
stat = stat,
geom = GeomPointRast,
position = position,
show.legend = show.legend,
inherit.aes = inherit.aes,
params = list(na.rm = na.rm,
raster.width = raster.width,
raster.height = raster.height,
raster.dpi = raster.dpi,
...)
)
geom_beeswarm_rast <- function(..., priority= c("ascending", "descending", "density", "random", "none"), cex = 1, groupOnX = NULL, dodge.width = 0, raster.dpi = 300, dev="cairo") {
rasterise(ggbeeswarm::geom_beeswarm(..., priority=priority, cex=cex, groupOnX=groupOnX, dodge.width=dodge.width), dpi=raster.dpi, dev=dev)
}

43 changes: 23 additions & 20 deletions R/geom-boxplot-jitter.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
DrawGeomBoxplotJitter <- function(data, panel_params, coord, ...,

GeomPointRast <- ggplot2::ggproto(
"GeomPointRast",
ggplot2::GeomPoint,
draw_panel = function(self, data, panel_params, coord, raster.dpi, dev) {
grob <- ggproto_parent(GeomPoint, self)$draw_panel(data, panel_params, coord)
class(grob) <- c("rasteriser", class(grob))
grob$dpi <- raster.dpi
grob$dev <- dev
return(grob)
}
)

DrawGeomBoxplotJitter <- function(data, panel_params, coord, dev="cairo", ...,
outlier.jitter.width=NULL,
outlier.jitter.height=0,
outlier.colour = NULL,
Expand Down Expand Up @@ -44,12 +57,7 @@ DrawGeomBoxplotJitter <- function(data, panel_params, coord, ...,
stringsAsFactors = FALSE
)

if (raster) {
boxplot_grob$children[[point_grob]] <- GeomPointRast$draw_panel(outliers, panel_params, coord, raster.width=raster.width,
raster.height=raster.height, raster.dpi=raster.dpi)
} else {
boxplot_grob$children[[point_grob]] <- ggplot2::GeomPoint$draw_panel(outliers, panel_params, coord)
}
boxplot_grob$children[[point_grob]] <- GeomPointRast$draw_panel(outliers, panel_params, coord, raster.dpi=raster.dpi, dev=dev)

return(boxplot_grob)
}
Expand All @@ -64,13 +72,11 @@ GeomBoxplotJitter <- ggplot2::ggproto("GeomBoxplotJitter",
#' @inheritSection ggplot2::geom_boxplot Aesthetics
#'
#' @param outlier.jitter.width Amount of horizontal jitter. The jitter is added in both positive and negative directions,
#' so the total spread is twice the value specified here. Default: boxplot width.
#' so the total spread is twice the value specified here (default=NULL)
#' @param outlier.jitter.height Amount of horizontal jitter. The jitter is added in both positive and negative directions,
#' so the total spread is twice the value specified here. Default: 0.
#' @param raster Should outlier points be rastered?.
#' @param raster.dpi Resolution of the rastered image. Ignored if \code{raster == FALSE}.
#' @param raster.width Width of the result image (in inches). Default: deterined by the current device parameters. Ignored if \code{raster == FALSE}.
#' @param raster.height Height of the result image (in inches). Default: deterined by the current device parameters. Ignored if \code{raster == FALSE}.
#' so the total spread is twice the value specified here (default=0)
#' @param raster.dpi Resolution of the rastered image (default=300). Ignored if \code{raster == FALSE}.
#' @param dev A character specifying a device (default="cairo"). Can be one of: \code{"cairo"}, \code{"ragg"} or \code{"ragg_png"}.
#' @return geom_boxplot plot with rasterized layer
#'
#' @examples
Expand All @@ -82,22 +88,19 @@ GeomBoxplotJitter <- ggplot2::ggproto("GeomBoxplotJitter",
#' ggplot() + geom_boxplot_jitter(aes(y=yvalues, x=xvalues), outlier.jitter.width = 0.1, raster = TRUE)
#'
#' @export
geom_boxplot_jitter <- function(mapping = NULL, data = NULL,
geom_boxplot_jitter <- function(mapping = NULL, data = NULL, dev = "cairo",
stat = "boxplot", position = "dodge",
na.rm = FALSE, show.legend = NA,
inherit.aes = TRUE, ...,
outlier.jitter.width=NULL,
outlier.jitter.height=0,
raster=FALSE, raster.dpi=300,
raster.width=NULL, raster.height=NULL
raster.dpi=300
) {
ggplot2::layer(
geom = GeomBoxplotJitter, mapping = mapping, data = data, stat = stat,
position = position, show.legend = show.legend, inherit.aes = inherit.aes,
params = list(na.rm = na.rm,
outlier.jitter.width=outlier.jitter.width,
outlier.jitter.height=outlier.jitter.height,
raster=raster, raster.dpi=raster.dpi,
raster.width=raster.width, raster.height=raster.height,
...))
}
raster.dpi=raster.dpi, dev=dev, ...))
}
40 changes: 5 additions & 35 deletions R/geom-jitter-rast.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
#' @inheritParams geom_point_rast
#' @inheritSection ggplot2::geom_point Aesthetics
#' @import ggplot2
#' @param width Amount of vertical and horizontal jitter. The jitter is added in both positive and negative directions, so the total spread is twice the value specified here. Refer to ggplot2::position_jitter.
#' @param height Amount of vertical and horizontal jitter. The jitter is added in both positive and negative directions, so the total spread is twice the value specified here. Refer to ggplot2::position_jitter.
#' @param seed A random seed to make the jitter reproducible. Refer to ggplot2::position_jitter.
#' @param raster.dpi An integer of length one setting the desired resolution in dots per inch. (default=NULL)
#' @param dev A character specifying a device. Can be one of: \code{"cairo"}, \code{"ragg"} or \code{"ragg_png"}. (default="cairo")
#' @return geom_point_rast plot with rasterized layer
#'
#' @examples
Expand All @@ -15,35 +14,6 @@
#' ggplot(mpg) + geom_jitter_rast(aes(x = factor(cyl), y = hwy), raster.dpi = 600)
#'
#' @export
geom_jitter_rast <- function(
mapping = NULL,
data = NULL,
stat = 'identity',
position = 'jitter',
width = NULL,
height = NULL,
seed = NA,
...,
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE,
raster.width = NULL, raster.height = NULL, raster.dpi = 300
) {

position = ggplot2::position_jitter(width = NULL, height = NULL, seed = NA)

ggplot2::layer(
data = data,
mapping = mapping,
stat = stat,
geom = GeomPointRast,
position = position,
show.legend = show.legend,
inherit.aes = inherit.aes,
params = list(na.rm = na.rm,
raster.width = raster.width,
raster.height = raster.height,
raster.dpi = raster.dpi,
...)
)
}
geom_jitter_rast <- function(..., raster.dpi = 300, dev="cairo"){
rasterise(geom_jitter(...), dpi=raster.dpi, dev=dev)
}
65 changes: 4 additions & 61 deletions R/geom-point-rast.R
Original file line number Diff line number Diff line change
@@ -1,47 +1,11 @@
#' @importFrom grDevices dev.cur dev.off dev.set
#' @importFrom graphics par
DrawGeomPointRast <- function(data, panel_params, coord, na.rm = FALSE, raster.width=NULL, raster.height=NULL, raster.dpi=300) {
if (is.null(raster.width)) {
raster.width <- par('fin')[1]
}

if (is.null(raster.height)) {
raster.height <- par('fin')[2]
}

prev_dev_id <- dev.cur()

p <- ggplot2::GeomPoint$draw_panel(data, panel_params, coord)
dev_id <- Cairo::Cairo(type='raster', width=raster.width*raster.dpi, height=raster.height*raster.dpi, dpi=raster.dpi, units='px', bg="transparent")[1]

grid::pushViewport(grid::viewport(width=1, height=1))
grid::grid.points(x=p$x, y=p$y, pch = p$pch, size = p$size,
name = p$name, gp = p$gp, vp = p$vp, draw = T)
grid::popViewport()
cap <- grid::grid.cap()
dev.off(dev_id)
dev.set(prev_dev_id)

grid::rasterGrob(cap, x=0, y=0, width = 1,
height = 1, default.units = "native",
just = c("left","bottom"))
}

GeomPointRast <- ggplot2::ggproto(
"GeomPointRast",
ggplot2::GeomPoint,
draw_panel = DrawGeomPointRast
)

#' This geom is similar to \code{\link[ggplot2]{geom_point}}, but creates a raster layer
#'
#' @inheritParams ggplot2::geom_point
#' @inheritSection ggplot2::geom_point Aesthetics
#'
#' @import ggplot2
#' @param raster.width Width of the result image (in inches). Default: deterined by the current device parameters.
#' @param raster.height Height of the result image (in inches). Default: deterined by the current device parameters.
#' @param raster.dpi Resolution of the result image.
#' @param raster.dpi An integer of length one setting the desired resolution in dots per inch. (default=NULL)
#' @param dev A character specifying a device. Can be one of: \code{"cairo"}, \code{"ragg"} or \code{"ragg_png"}. (default="cairo")
#' @return geom_point plot with rasterized layer
#'
#' @examples
Expand All @@ -51,27 +15,6 @@ GeomPointRast <- ggplot2::ggproto(
#' ggplot() + geom_point_rast(aes(x=rnorm(1000), y=rnorm(1000)), raster.dpi=600)
#'
#' @export
geom_point_rast <- function(mapping = NULL,
data = NULL,
stat = "identity",
position = "identity",
...,
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE,
raster.width=NULL, raster.height=NULL, raster.dpi=300) {
ggplot2::layer(
data = data,
mapping = mapping,
stat = stat,
geom = GeomPointRast,
position = position,
show.legend = show.legend,
inherit.aes = inherit.aes,
params = list(na.rm = na.rm,
raster.width=raster.width,
raster.height=raster.height,
raster.dpi=raster.dpi,
...)
)
geom_point_rast <- function(..., raster.dpi=300, dev="cairo") {
rasterise(geom_point(...), dpi=raster.dpi, dev=dev)
}
Loading