-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
91 lines (71 loc) · 2.89 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
91
---
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%"
)
```
# asn <a href="https://asndataanalytics.github.io/asn/"><img src="man/figures/logo.png" align="right" height="138" /></a>
<!-- badges: start -->
<!-- badges: end -->
The **`asn`** package provides functions to use the brand identity of the [American Society of Nephrology](https://asn-online.org) (ASN) in data visualizations made in either `ggplot2` or `highcharter`. It also provides some helper functions:
- `pct_chg()` and `pct_norm()` calculate percentage changes from either previous values or the first value in a series
- `pct_fun()` returns a summary count table for a vector including the percentage breakdowns in a easily readable format
- `get_labs()` extracts the label attributes from an object. This is designed to pull the questions from the column names from a data frame extracted by `haven` from Qualtrics SPSS .sav files
- `select_all()` counts the number of unique responses to "Select All" questions which are separated across columns in Qualtrics data
The original inspiration for the package came from Dr. Simon Jackson's blog post: <https://drsimonj.svbtle.com/creating-corporate-colour-palettes-for-ggplot2>. It's highly recommended reading and the `scale_*_asn_ramp()` functions are copied from it. However, I didn't want to always use interpolated colors (created by `colorRampPalette`) so I "borrowed" Matt Dancho's approach from his `tidyquant` package, viewable at <https://github.com/business-science/tidyquant/blob/master/R/ggplot-scale_manual.R> for the `scale_*_asn()` functions.
Creation of this package was heavily informed by R Packages (2e) by Hadley Wickham and Jenny Bryan available at <https://r-pkgs.org/>.
## Installation
You can install the development version of asn from [GitHub](https://github.com/) with:
``` r
# install.packages("devtools")
devtools::install_github("ASNDataAnalytics/asn")
```
## Example
To use ASN for visualizing data in `ggplot2`:
```{r example, message=FALSE}
library(asn)
library(ggplot2)
ggplot(
iris,
aes(
x = Sepal.Length,
y = Petal.Length,
color = Species
)
) +
geom_point() +
geom_smooth(
method = "lm",
se = FALSE
) +
scale_color_asn(palette = "dark_mode") +
theme(
panel.background = element_rect(color = "#000000", fill = "#000000"),
plot.background = element_rect(color = "#000000", fill = "#000000"),
panel.grid = element_blank()
)
```
And a similar application in `highcharter` (not shown)
```{r eval=FALSE}
library(highcharter)
library(asn)
highchart() |>
hc_add_series(
data = iris,
type = "scatter",
hcaes(
x = Sepal.Length,
y = Sepal.Width,
group = Species
)
) |>
hc_add_theme(
asn_theme
)
```