Skip to content

Commit

Permalink
Add png_retina function, bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
ateucher committed Sep 21, 2017
1 parent 410ac0c commit 07afe83
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 2 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: envreportutils
Type: Package
Title: Utilities for common operations, mainly plotting
Version: 0.4.1
Date: 2017-01-19
Version: 0.6.0
Date: 2017-09-21
Authors@R: c(person("Andy", "Teucher", role = c("aut", "cre"), email =
"andy.teucher@gov.bc.ca"),
person("Stephanie", "Hazlitt", role = "aut",
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export(get_data_licence)
export(get_data_license)
export(multiplot)
export(order_df)
export(png_retina)
export(theme_soe)
export(theme_soe_facet)
import(extrafont)
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# envreportutils 0.6.0

* Added function `png_retina()` - a drop in replacement for `png()` to produce
retina-quality graphics.

# envreportutils 0.5.1

* Two functions deprecated, functionality available in other CRAN packages.
Expand Down
37 changes: 37 additions & 0 deletions R/png_retina.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#' Create png for retina display
#'
#' This is a drop-in replacement for the \code{\link[grDevices]{png}} function
#' for creating images for the web for retina devices. Internally, it simply
#' doubles the width, height, and resolution specified. The intention is then
#' that in the webpage that you would specify the \code{width} and \code{height}
#' attributes in the html at the original resolution.
#'
#' @inheritParams grDevices::png
#'
#' @return A plot device is opened: nothing is returned to the R interpreter.
#' @export
#'
#' @seealso \code{\link[grDevices]{png}}
#'
#' @examples
#'
#' # You want to display at 500 * 500 in the web:
#' png_retina("myplot.png", width = 500, height = 500)
#' plot(x = 1:500, y = rnorm(500))
#' dev.off()
#'
#' # Although the output image will be 1000 * 1000, in the html you would put:
#' # <img src="myplot.png", width="500", height="500" />
#'
png_retina <- function(filename = "Rplot%03d.png", width = 480, height = 480,
units = "px", pointsize = 12, bg = "white", res = NA,
..., type = c("cairo", "cairo-png", "Xlib", "quartz"),
antialias) {
height <- height * 2
width <- width * 2
res <- ifelse(is.na(res), 144, res * 2)

grDevices::png(filename = filename, width = width, height = height,
units = units, pointsize = pointsize, bg = bg, res = res, ...,
type = type, antialias = antialias)
}
82 changes: 82 additions & 0 deletions man/png_retina.Rd

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

0 comments on commit 07afe83

Please sign in to comment.