diff --git a/DESCRIPTION b/DESCRIPTION index b50ff00..a82de75 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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", diff --git a/NAMESPACE b/NAMESPACE index 4a36222..e8acab2 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -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) diff --git a/NEWS.md b/NEWS.md index 022bab4..57452c0 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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. diff --git a/R/png_retina.R b/R/png_retina.R new file mode 100644 index 0000000..18dc2ae --- /dev/null +++ b/R/png_retina.R @@ -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: +#' # +#' +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) +} diff --git a/man/png_retina.Rd b/man/png_retina.Rd new file mode 100644 index 0000000..1b2ac0f --- /dev/null +++ b/man/png_retina.Rd @@ -0,0 +1,82 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/png_retina.R +\name{png_retina} +\alias{png_retina} +\title{Create png for retina display} +\usage{ +png_retina(filename = "Rplot\%03d.png", width = 480, height = 480, + units = "px", pointsize = 12, bg = "white", res = NA, ..., + type = c("cairo", "cairo-png", "Xlib", "quartz"), antialias) +} +\arguments{ +\item{filename}{the name of the output file. + The page number is substituted if a C integer format is included in + the character string, as in the default. (The result must be less + than \code{PATH_MAX} characters long, and may be truncated if not. + See \code{\link{postscript}} for further details.) Tilde expansion + is performed where supported by the platform.} + +\item{width}{the width of the device.} + +\item{height}{the height of the device.} + +\item{units}{The units in which \code{height} and \code{width} are + given. Can be \code{px} (pixels, the default), \code{in} (inches), + \code{cm} or \code{mm}.} + +\item{pointsize}{the default pointsize of plotted text, interpreted as + big points (1/72 inch) at \code{res} ppi.} + +\item{bg}{the initial background colour: can be overridden by setting + par("bg").} + +\item{res}{The nominal resolution in ppi which will be recorded in the + bitmap file, if a positive integer. Also used for \code{units} + other than the default, and to convert points to pixels.} + +\item{...}{for \code{type = "Xlib"} only, additional arguments to + the underlying \code{\link{X11}} device such as \code{fonts} or + \code{family}. + + For types \code{"cairo"} and \code{"quartz"}, the \code{family} + argument can be supplied. See the \sQuote{Cairo fonts} + section in the help for \code{\link{X11}}.} + +\item{type}{character string, one of \code{"Xlib"} or \code{"quartz"} + (some macOS builds) or \code{"cairo"}. The latter will only be + available if the system was compiled with support for cairo -- + otherwise \code{"Xlib"} will be used. The default is set by + \code{\link{getOption}("bitmapType")} -- the \sQuote{out of the box} + default is \code{"quartz"} or \code{"cairo"} where available, + otherwise \code{"Xlib"}.} + +\item{antialias}{for \code{type = "cairo"}, giving the type of + anti-aliasing (if any) to be used for fonts and lines (but not + fills). See \code{\link{X11}}. The default is set by + \code{\link{X11.options}}. Also for \code{type = "quartz"}, where + antialiasing is used unless \code{antialias = "none"}.} +} +\value{ +A plot device is opened: nothing is returned to the R interpreter. +} +\description{ +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. +} +\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: +# + +} +\seealso{ +\code{\link[grDevices]{png}} +}