-
Notifications
You must be signed in to change notification settings - Fork 23
/
README.Rmd
91 lines (65 loc) · 2.24 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{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
<!-- badges: start -->
[![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)
<!-- badges: end -->
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).