Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yutannihilation/gghighlight
Highlight points and lines in ggplot2
https://github.com/yutannihilation/gghighlight
Last synced: 4 days ago
JSON representation
Highlight points and lines in ggplot2
- Host: GitHub
- URL: https://github.com/yutannihilation/gghighlight
- Owner: yutannihilation
- License: other
- Created: 2017-05-27T13:19:16.000Z (over 7 years ago)
- Default Branch: main
- Last Pushed: 2024-09-06T23:06:13.000Z (5 months ago)
- Last Synced: 2025-01-30T20:55:13.187Z (11 days ago)
- Language: R
- Homepage: https://yutannihilation.github.io/gghighlight/
- Size: 44.1 MB
- Stars: 524
- Watchers: 11
- Forks: 23
- Open Issues: 17
-
Metadata Files:
- Readme: README.Rmd
- Changelog: NEWS.md
- License: LICENSE
Awesome Lists containing this project
- awesome-r-dataviz - gghighlight - Highlight points and lines in ggplot2. (ggplot / Miscellaneous)
README
---
output: github_document
---```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-"
)# if ragg is installed, use it.
if (requireNamespace("ragg", quietly = TRUE)) {
knitr::opts_chunk$set(
dev = "ragg_png"
)
}
```# gghighlight
[![R build status](https://github.com/yutannihilation/gghighlight/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/yutannihilation/gghighlight/actions/workflows/R-CMD-check.yaml)
[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/gghighlight)](https://cran.r-project.org/package=gghighlight)Highlight geoms in ggplot2.
## Installation
```{r gh-installation, eval = FALSE}
install.packages("gghighlight")# Or the development version from GitHub:
# install.packages("devtools")
devtools::install_github("yutannihilation/gghighlight")
```## Example
(For the full version, please refer to [Introduction to gghighlight](https://yutannihilation.github.io/gghighlight/articles/gghighlight.html)).
Suppose we have a data that has so many series that it is hard to identify them by their colours as the differences are so subtle.
```{r data, include=FALSE}
set.seed(2)
d <- purrr::map_dfr(
letters,
~ data.frame(
idx = 1:400,
value = cumsum(runif(400, -1, 1)),
type = .,
flag = sample(c(TRUE, FALSE), size = 400, replace = TRUE),
stringsAsFactors = FALSE
)
)
``````{r ggplot2-simple}
library(ggplot2)ggplot(d) +
geom_line(aes(idx, value, colour = type))
```With `gghighlight()`, we can highlight the lines whose max values are larger than 20:
```{r gghighlight-simple}
library(gghighlight)p <- ggplot(d) +
geom_line(aes(idx, value, colour = type)) +
gghighlight(max(value) > 20)p
```The result is a usual ggplot object, so it is fully customizable. For example, it can be used with custom themes and facets.
```{r gghighlight-theme-facets}
p + theme_minimal()p + theme_minimal() + facet_wrap(~ type)
````gghighlight()` can highlight almost any geoms. For more details, please read [Introduction to gghighlight](https://yutannihilation.github.io/gghighlight/articles/gghighlight.html).