-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME.Rmd
63 lines (47 loc) · 1.29 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
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
library("ggisotonic")
```
# ggisotonic
<!-- badges: start -->
<!-- badges: end -->
`ggisotonic` introduces a ggplot layer `stat_isotonic` to add isotonic or monotonic regression curves similar to `ggplot2::geom_smooth`.
## Installation
```{r, eval = FALSE}
install.packages("ggisotonic")
library("ggisotonic")
```
You can install the released version of ggisotonic from github with:
```{r, eval = FALSE}
remotes::install_github("talegari/ggisotonic")
```
## Example
```{r example}
library("ggplot2")
set.seed(100)
dataset = data.frame(x = sort(runif(1e2)),
y = c(rnorm(1e2/2), rnorm(1e2/2, mean = 4)),
w = sample(1:3, 1e2, replace = TRUE)
)
print(head(dataset))
```
```{r}
# plot isotonic regression line
ggplot(dataset, aes(x = x, y = y)) +
geom_point() +
stat_isotonic()
# plot weighted isotonic regression line along with facets
ggplot(dataset, aes(x = x, y = y)) +
geom_point() +
stat_isotonic(aes(w = w), color = 'red', size = 1.5, show.legend = FALSE) +
facet_wrap(w ~ .)
```