Skip to content

Commit

Permalink
major cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
clauswilke committed Jan 11, 2020
1 parent 130ac33 commit af57c2c
Show file tree
Hide file tree
Showing 180 changed files with 12,167 additions and 2,335 deletions.
3 changes: 3 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ visual_test
^\.Rproj\.user$
^\.travis\.yml$
^\.codecov\.yml$
^_pkgdown\.yml$
^ISSUE_TEMPLATE\.md$
^README\.Rmd$
^cran-comments.md$
^TODO\.Rmd$
^docs$
^revdep$
^appveyor\.yml$
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
language: r
cache: packages

matrix:
include:
- r: devel
- r: release

after_success:
- Rscript -e 'covr::codecov()'
27 changes: 15 additions & 12 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
Package: ggridges
Type: Package
Title: Ridgeline Plots in 'ggplot2'
Version: 0.5.1.9000
Authors@R: c(
person("Claus O.", "Wilke", , "[email protected]", c("cre", "aut")),
person("RStudio", role = c("cph"), comment = "Copyright for ggplot2 code copied to ggridges"))
Version: 0.5.2.9000
Authors@R:
person(
given = "Claus O.",
family = "Wilke",
role = c("aut", "cre"),
email = "[email protected]",
comment = c(ORCID = "0000-0002-7470-9261")
)
Description: Ridgeline plots provide a convenient way of visualizing changes in distributions over time or space. This package enables the creation of such plots in 'ggplot2'.
URL: https://github.com/clauswilke/ggridges
URL: https://wilkelab.org/ggridges
BugReports: https://github.com/wilkelab/ggridges/issues
Depends:
R (>= 3.2)
Imports:
ggplot2 (>= 2.2.0),
ggplot2 (>= 3.0.0),
grid (>= 3.0.0),
plyr (>= 1.8.0),
scales (>= 0.4.1),
Expand All @@ -20,15 +26,13 @@ LazyData: true
Suggests:
covr,
dplyr,
gridExtra,
patchwork,
ggplot2movies,
DAAG,
forcats,
knitr,
rmarkdown,
testthat,
vdiffr,
viridis
vdiffr
VignetteBuilder: knitr
Collate:
'data.R'
Expand All @@ -38,13 +42,12 @@ Collate:
'geoms-gradient.R'
'geom-density-line.R'
'position.R'
'scale-.R'
'scale-cyclical.R'
'scale-point.R'
'scale-vline.R'
'stats.R'
'theme.R'
'utils_ggplot2.R'
'utils.R'
RoxygenNote: 6.1.0
RoxygenNote: 7.0.2
Roxygen: list(markdown = TRUE)
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export(position_raincloud)
export(scale_alpha_cyclical)
export(scale_color_cyclical)
export(scale_colour_cyclical)
export(scale_discrete_manual)
export(scale_fill_cyclical)
export(scale_linetype_cyclical)
export(scale_point_color_continuous)
Expand Down
3 changes: 3 additions & 0 deletions NEWS → NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
ggridges 0.5.1.9000
----------------------------------------------------------------
- There is now a project website at https://wilkelab.org/ggridges
- `scale_discrete_manual()` has been removed, as it has been available in
ggplot2 since version 3.0.0.
- `stat_density_ridges()` now has a parameter `n` that determines at how many
points along the x axis the density is estimated.

Expand Down
12 changes: 12 additions & 0 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,15 @@
#' \item{`Percent`}{The percentage of the voters choosing the given option}
#' }
"Catalan_elections"

#' Australian athletes
#'
#' This dataset is equivalent to `ais` from the `DAAG` package.
#'
#' @references
#' Telford, R.D. and Cunningham, R.B. 1991. Sex, sport and body-size dependency of hematology in
#' highly trained athletes. Medicine and Science in Sports and Exercise 23: 788-794.
#'
#' @examples
#' # none yet
"Aus_athletes"
23 changes: 13 additions & 10 deletions R/geoms-gradient.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@
#' library(ggplot2)
#'
#' # Example for `geom_ridgeline_gradient()`
#' library(viridis)
#' d <- data.frame(x = rep(1:5, 3) + c(rep(0, 5), rep(0.3, 5), rep(0.6, 5)),
#' y = c(rep(0, 5), rep(1, 5), rep(3, 5)),
#' height = c(0, 1, 3, 4, 0, 1, 2, 3, 5, 4, 0, 5, 4, 4, 1))
#' d <- data.frame(
#' x = rep(1:5, 3) + c(rep(0, 5), rep(0.3, 5), rep(0.6, 5)),
#' y = c(rep(0, 5), rep(1, 5), rep(3, 5)),
#' height = c(0, 1, 3, 4, 0, 1, 2, 3, 5, 4, 0, 5, 4, 4, 1)
#' )
#' ggplot(d, aes(x, y, height = height, group = y, fill = factor(x+y))) +
#' geom_ridgeline_gradient() +
#' scale_fill_viridis(discrete = TRUE, direction = -1) +
#' scale_fill_viridis_d(direction = -1) +
#' theme(legend.position = 'none')
#' @importFrom ggplot2 layer
#' @export
Expand Down Expand Up @@ -410,13 +411,15 @@ geom_density_ridges_gradient <- function(mapping = NULL, data = NULL, stat = "de
#' @examples
#'
#' # Example for `geom_density_ridges_gradient()`
#' ggplot(lincoln_weather, aes(x = `Mean Temperature [F]`, y = `Month`, fill = ..x..)) +
#' ggplot(lincoln_weather, aes(x = `Mean Temperature [F]`, y = `Month`, fill = stat(x))) +
#' geom_density_ridges_gradient(scale = 3, rel_min_height = 0.01) +
#' scale_x_continuous(expand = c(0.01, 0)) +
#' scale_y_discrete(expand = c(0.01, 0)) +
#' scale_fill_viridis(name = "Temp. [F]", option = "C") +
#' scale_x_continuous(expand = c(0, 0)) +
#' scale_y_discrete(expand = c(0, 0)) +
#' scale_fill_viridis_c(name = "Temp. [F]", option = "C") +
#' coord_cartesian(clip = "off") +
#' labs(title = 'Temperatures in Lincoln NE in 2016') +
#' theme_ridges(font_size = 13, grid = TRUE) + theme(axis.title.y = element_blank())
#' theme_ridges(font_size = 13, grid = TRUE) +
#' theme(axis.title.y = element_blank())
#' @export
GeomDensityRidgesGradient <- ggproto("GeomDensityRidgesGradient", GeomRidgelineGradient,
default_aes = aes(
Expand Down
37 changes: 0 additions & 37 deletions R/scale-.R

This file was deleted.

103 changes: 65 additions & 38 deletions R/stats.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#' and sets it to `TRUE`.
#' @param calc_ecdf If `TRUE`, `stat_density_ridges` calculates an empirical cumulative distribution function (ecdf)
#' and returns a variable `ecdf` and a variable `quantile`. Both can be mapped onto aesthetics via
#' `..ecdf..` and `..quantile..`, respectively.
#' `stat(ecdf)` and `stat(quantile)`, respectively.
#' @param quantiles Sets the number of quantiles the data should be broken into. Used if either `calc_ecdf = TRUE`
#' or `quantile_lines = TRUE`. If `quantiles` is an integer then the data will be cut into that many equal quantiles.
#' If it is a vector of probabilities then the data will cut by them.
Expand All @@ -32,25 +32,37 @@
#' library(ggplot2)
#'
#' # Examples of coloring by ecdf or quantiles
#' library(viridis)
#' ggplot(iris, aes(x=Sepal.Length, y=Species, fill=factor(..quantile..))) +
#' stat_density_ridges(geom = "density_ridges_gradient", calc_ecdf = TRUE,
#' quantiles = 5) +
#' scale_fill_viridis(discrete = TRUE, name = "Quintiles") + theme_ridges() +
#' scale_y_discrete(expand = c(0.01, 0))
#' ggplot(iris, aes(x = Sepal.Length, y = Species, fill = factor(stat(quantile)))) +
#' stat_density_ridges(
#' geom = "density_ridges_gradient",
#' calc_ecdf = TRUE,
#' quantiles = 5
#' ) +
#' scale_fill_viridis_d(name = "Quintiles") +
#' theme_ridges()
#'
#' ggplot(iris, aes(x=Sepal.Length, y=Species, fill=0.5 - abs(0.5-..ecdf..))) +
#' ggplot(iris,
#' aes(
#' x = Sepal.Length, y = Species, fill = 0.5 - abs(0.5-stat(ecdf))
#' )) +
#' stat_density_ridges(geom = "density_ridges_gradient", calc_ecdf = TRUE) +
#' scale_fill_viridis(name = "Tail probability", direction = -1) + theme_ridges() +
#' scale_y_discrete(expand = c(0.01, 0))
#' scale_fill_viridis_c(name = "Tail probability", direction = -1) +
#' theme_ridges()
#'
#' ggplot(iris, aes(x=Sepal.Length, y=Species, fill=factor(..quantile..))) +
#' stat_density_ridges(geom = "density_ridges_gradient",
#' calc_ecdf = TRUE, quantiles = c(0.025, 0.975)) +
#' scale_fill_manual(name = "Probability",
#' values = c("#FF0000A0", "#A0A0A0A0", "#0000FFA0"),
#' labels = c("(0, 0.025]", "(0.025, 0.975]", "(0.975, 1]")) +
#' theme_ridges() + scale_y_discrete(expand = c(0.01, 0))
#' ggplot(iris,
#' aes(
#' x = Sepal.Length, y = Species, fill = factor(stat(quantile))
#' )) +
#' stat_density_ridges(
#' geom = "density_ridges_gradient",
#' calc_ecdf = TRUE, quantiles = c(0.025, 0.975)
#' ) +
#' scale_fill_manual(
#' name = "Probability",
#' values = c("#FF0000A0", "#A0A0A0A0", "#0000FFA0"),
#' labels = c("(0, 0.025]", "(0.025, 0.975]", "(0.975, 1]")
#' ) +
#' theme_ridges()
#' @export
stat_density_ridges <- function(mapping = NULL, data = NULL, geom = "density_ridges",
position = "identity", na.rm = FALSE, show.legend = NA,
Expand Down Expand Up @@ -297,42 +309,57 @@ StatDensityRidges <- ggproto("StatDensityRidges", Stat,
#'
#' ggplot(iris, aes(x = Sepal.Length, y = Species, group = Species, fill = Species)) +
#' geom_density_ridges(stat = "binline", bins = 20, scale = 2.2) +
#' scale_y_discrete(expand = c(0.01, 0)) +
#' scale_x_continuous(expand = c(0.01, 0)) +
#' scale_y_discrete(expand = c(0, 0)) +
#' scale_x_continuous(expand = c(0, 0)) +
#' coord_cartesian(clip = "off") +
#' theme_ridges()
#'
#' ggplot(iris, aes(x = Sepal.Length, y = Species, group = Species, fill = Species)) +
#' stat_binline(bins = 20, scale = 2.2, draw_baseline = FALSE) +
#' scale_y_discrete(expand = c(0.01, 0)) +
#' scale_x_continuous(expand = c(0.01, 0)) +
#' scale_y_discrete(expand = c(0, 0)) +
#' scale_x_continuous(expand = c(0, 0)) +
#' scale_fill_grey() +
#' theme_ridges() + theme(legend.position = 'none')
#' coord_cartesian(clip = "off") +
#' theme_ridges() +
#' theme(legend.position = 'none')
#'
#' require(ggplot2movies)
#' require(viridis)
#' library(ggplot2movies)
#' ggplot(movies[movies$year>1989,], aes(x = length, y = year, fill = factor(year))) +
#' stat_binline(scale = 1.9, bins = 40) +
#' theme_ridges() + theme(legend.position = "none") +
#' scale_x_continuous(limits = c(1, 180), expand = c(0.01, 0)) +
#' scale_y_reverse(expand = c(0.01, 0)) +
#' scale_fill_viridis(begin = 0.3, discrete = TRUE, option = "B") +
#' scale_x_continuous(limits = c(1, 180), expand = c(0, 0)) +
#' scale_y_reverse(expand = c(0, 0)) +
#' scale_fill_viridis_d(begin = 0.3, option = "B") +
#' coord_cartesian(clip = "off") +
#' labs(title = "Movie lengths 1990 - 2005")
#' theme_ridges() +
#' theme(legend.position = "none")
#'
#' count_data <- data.frame(group = rep(letters[1:5], each = 10),
#' mean = rep(1:5, each = 10))
#' count_data <- data.frame(
#' group = rep(letters[1:5], each = 10),
#' mean = rep(1:5, each = 10)
#' )
#' count_data$group <- factor(count_data$group, levels = letters[5:1])
#' count_data$count <- rpois(nrow(count_data), count_data$mean)
#'
#' ggplot(count_data, aes(x = count, y = group, group = group)) +
#' geom_density_ridges2(stat = "binline", aes(fill = group), binwidth = 1, scale = 0.95) +
#' geom_text(stat = "bin",
#' aes(y = group+0.9*..count../max(..count..),
#' label = ifelse(..count..>0, ..count.., "")),
#' vjust = 1.2, size = 3, color = "white", binwidth = 1) +
#' theme_ridges(grid = FALSE) +
#' geom_density_ridges2(
#' stat = "binline",
#' aes(fill = group),
#' binwidth = 1,
#' scale = 0.95
#' ) +
#' geom_text(
#' stat = "bin",
#' aes(y = group + 0.9*stat(count/max(count)),
#' label = ifelse(stat(count) > 0, stat(count), "")),
#' vjust = 1.2, size = 3, color = "white", binwidth = 1
#' ) +
#' scale_x_continuous(breaks = c(0:12), limits = c(-.5, 13), expand = c(0, 0)) +
#' scale_y_discrete(expand = c(0.01, 0)) +
#' scale_y_discrete(expand = c(0, 0)) +
#' scale_fill_cyclical(values = c("#0000B0", "#7070D0")) +
#' guides(y = "none")
#' guides(y = "none") +
#' coord_cartesian(clip = "off") +
#' theme_ridges(grid = FALSE)
#' @importFrom stats quantile
#' @export
stat_binline <- function(mapping = NULL, data = NULL,
Expand Down
27 changes: 13 additions & 14 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,31 @@ knitr::opts_chunk$set(

# ggridges

[![Build Status](https://travis-ci.org/clauswilke/ggridges.svg?branch=master)](https://travis-ci.org/clauswilke/ggridges)
<!-- badges: start -->
[![Build Status](https://travis-ci.org/wilkelab/ggridges.svg?branch=master)](https://travis-ci.org/wilkelab/ggridges)
[![AppVeyor build status](https://ci.appveyor.com/api/projects/status/github/wilkelab/ggridges?branch=master&svg=true)](https://ci.appveyor.com/project/clauswilke/ggridges)
[![Coverage Status](https://img.shields.io/codecov/c/github/clauswilke/ggridges/master.svg)](https://codecov.io/github/clauswilke/ggridges?branch=master)
[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/ggridges)](https://CRAN.R-project.org/package=ggridges)
[![CRAN_Downloads_Badge](http://cranlogs.r-pkg.org/badges/ggridges)](http://cranlogs.r-pkg.org/downloads/total/last-month/ggridges)
<!-- badges: end -->


Geoms to make ridgeline plots using ggplot2, written by Claus O. Wilke

This package has now been officially relased on CRAN. Most things should work as expected, and the API should now be relatively stable. For feedback and feature requests, please open issues on github.

## About ridgeline plots
Draw ridgeline plots using ggplot2.

Ridgeline plots are partially overlapping line plots that create the impression of a mountain range. They can be quite useful for visualizing changes in distributions over time or space. These types of plots have also been called ["joyplots"](
https://twitter.com/JennyBryan/status/856674638981550080), in reference to the [iconic cover art](https://blogs.scientificamerican.com/sa-visual/pop-culture-pulsar-origin-story-of-joy-division-s-unknown-pleasures-album-cover-video/) for Joy Division's album _Unknown Pleasures_. However, given the [unfortunate origin](https://en.wikipedia.org/wiki/House_of_Dolls) of the name Joy Division, the term "joyplot" is now discouraged.

## Installation

Stable release:
Please install the stable release from CRAN:

```{r eval = FALSE}
install.packages("ggridges")
```

Latest development version:
Alternatively, you can install the latest development version from github:

```{r eval = FALSE}
library(devtools)
install_github("clauswilke/ggridges")
remotes::install_github("wilkelab/ggridges")
```

## Usage
Expand All @@ -51,9 +48,11 @@ library(ggplot2)
library(ggridges)
ggplot(diamonds, aes(x = price, y = cut)) +
geom_density_ridges(scale = 4) + theme_ridges() +
scale_y_discrete(expand = c(0.01, 0)) + # will generally have to set the `expand` option
scale_x_continuous(expand = c(0, 0)) # for both axes to remove unneeded padding
geom_density_ridges(scale = 4) +
scale_y_discrete(expand = c(0, 0)) + # will generally have to set the `expand` option
scale_x_continuous(expand = c(0, 0)) + # for both axes to remove unneeded padding
coord_cartesian(clip = "off") + # to avoid clipping of the very top of the top ridgeline
theme_ridges()
```

## Documentation and Examples
Expand Down
Loading

0 comments on commit af57c2c

Please sign in to comment.