https://github.com/talegari/ggisotonic
Add isotonic or monotonic regression curves to ggplots
https://github.com/talegari/ggisotonic
Last synced: 4 months ago
JSON representation
Add isotonic or monotonic regression curves to ggplots
- Host: GitHub
- URL: https://github.com/talegari/ggisotonic
- Owner: talegari
- Created: 2021-11-14T19:48:25.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-05-23T16:26:49.000Z (about 4 years ago)
- Last Synced: 2025-12-09T17:38:25.790Z (6 months ago)
- Language: R
- Size: 82 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.Rmd
Awesome Lists containing this project
- awesome-ggplot2 - ggisotonic
README
---
output: github_document
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
library("ggisotonic")
```
# ggisotonic
`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 ~ .)
```