Skip to content

Improve docs for geom_contour as discussed in issue #4324 #4325

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

Merged
merged 7 commits into from
Jan 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ jobs:
if: runner.os == 'macOS'
run: |
# XQuartz is needed by vdiffr
brew cask install xquartz
brew install xquartz

# Use only binary packages
echo 'options(pkgType = "binary")' >> ~/.Rprofile
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
- name: Install system dependencies on macOS
run: |
# XQuartz is needed by vdiffr
brew cask install xquartz
brew install xquartz

- name: Install dependencies
run: |
Expand Down
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Suggests:
ggplot2movies,
hexbin,
Hmisc,
interp,
knitr,
lattice,
mapproj,
Expand Down
38 changes: 29 additions & 9 deletions R/geom-contour.r
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
#' 2D contours of a 3D surface
#'
#' ggplot2 can not draw true 3D surfaces, but you can use `geom_contour()`,
#' `geom_contour_filled()`, and [geom_tile()] to visualise 3D surfaces in 2D.
#' To specify a valid surface, the data must contain `x`, `y`, and `z` coordinates,
#' and each unique combination of `x` and `y` can appear exactly once. Contouring
#' tends to work best when `x` and `y` form a (roughly) evenly
#' spaced grid. If your data is not evenly spaced, you may want to interpolate
#' to a grid before visualising, see [geom_density_2d()].
#' `geom_contour_filled()`, and [geom_tile()] to visualise 3D surfaces in 2D. To
#' specify a valid surface, the data must contain `x`, `y`, and `z` coordinates,
#' and each unique combination of `x` and `y` can appear at most once.
#' Contouring requires that the points can be rearranged so that the `z` values
#' form a matrix, with rows corresponding to unique `x` values, and columns
#' corresponding to unique `y` values. Missing entries are allowed, but contouring
#' will only be done on cells of the grid with all four `z` values present. If
#' your data is irregular, you can interpolate to a grid before visualising
#' using the [interp::interp()] function from the `interp` package
#' (or one of the interpolating functions from the `akima` package.)
#'
#' @eval rd_aesthetics("geom", "contour")
#' @eval rd_aesthetics("geom", "contour_filled")
Expand All @@ -15,9 +19,9 @@
#' @inheritParams geom_path
#' @param bins Number of contour bins. Overridden by `binwidth`.
#' @param binwidth The width of the contour bins. Overridden by `breaks`.
#' @param breaks Numeric vector to set the contour breaks.
#' Overrides `binwidth` and `bins`. By default, this is a vector of
#' length ten with [pretty()] breaks.
#' @param breaks Numeric vector to set the contour breaks. Overrides `binwidth`
#' and `bins`. By default, this is a vector of length ten with [pretty()]
#' breaks.
#' @seealso [geom_density_2d()]: 2d density contours
#' @export
#' @examples
Expand Down Expand Up @@ -47,6 +51,22 @@
#' v + geom_contour(colour = "red")
#' v + geom_raster(aes(fill = density)) +
#' geom_contour(colour = "white")
#'
#' # Irregular data
#' if (requireNamespace("interp")) {
#' # Use a dataset from the interp package
#' data(franke, package = "interp")
#' origdata <- as.data.frame(interp::franke.data(1, 1, franke))
#' grid <- with(origdata, interp::interp(x, y, z))
#' griddf <- subset(data.frame(x = rep(grid$x, nrow(grid$z)),
#' y = rep(grid$y, each = ncol(grid$z)),
#' z = as.numeric(grid$z)),
#' !is.na(z))
#' ggplot(griddf, aes(x, y, z = z)) +
#' geom_contour_filled() +
#' geom_point(data = origdata)
#' } else
#' message("Irregular data requires the 'interp' package")
#' }
geom_contour <- function(mapping = NULL, data = NULL,
stat = "contour", position = "identity",
Expand Down
2 changes: 1 addition & 1 deletion R/position-jitterdodge.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#' @inheritParams position_jitter
#' @export
#' @examples
#' dsub <- diamonds[ sample(nrow(diamonds), 1000), ]
#' dsub <- diamonds[sample(nrow(diamonds), 1000), ]
#' ggplot(dsub, aes(x = cut, y = carat, fill = clarity)) +
#' geom_boxplot(outlier.size = 0) +
#' geom_point(pch = 21, position = position_jitterdodge())
Expand Down
38 changes: 29 additions & 9 deletions man/geom_contour.Rd

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

6 changes: 3 additions & 3 deletions man/geom_density_2d.Rd

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

2 changes: 1 addition & 1 deletion man/position_jitterdodge.Rd

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

8 changes: 4 additions & 4 deletions tests/figs/coord-sf/sf-polygons.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/figs/deps.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
- vdiffr-svg-engine: 1.0
- vdiffr: 0.3.1
- vdiffr: 0.3.3
- freetypeharfbuzz: 0.2.5
Loading