-
Notifications
You must be signed in to change notification settings - Fork 4
/
README.Rmd
127 lines (88 loc) · 3.78 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
---
output:
md_document:
variant: gfm
---
[![R build status](https://github.com/m-clark/mixedup/workflows/R-CMD-check/badge.svg)](https://github.com/m-clark/mixedup/actions)
[![Coverage Status](https://img.shields.io/codecov/c/github/m-clark/visibly/master.svg)](https://codecov.io/github/m-clark/visibly?branch=master)
[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
[![Lifecycle Status](https://img.shields.io/badge/lifecycle-maturing-blue.svg)](https://www.tidyverse.org/lifecycle/)
```{r setup, echo=FALSE, include=FALSE, cache=FALSE}
knitr::opts_chunk$set(
echo = T,
message = F,
warning = F,
error = F,
collapse = TRUE,
comment = NA,
#R.options=list(width=220), # code
dev.args = list(bg = 'transparent'),
dev = 'png',
# viz
fig.path = "man/figures/README-",
fig.align = 'center',
out.width = '75%',
fig.asp = .75,
cache.rebuild = F,
cache = F
) # cache
```
# visibly
<img src="man/figures/visibly_hex.png" align="right" width = 200/>
Visibly is a handful of functions I use for color palettes, themes, etc. in R. Inside you will find:
- some ready-made palettes, e.g. based on R blue and Stan red
- a function to quickly and easily create palettes with using `colortools::complementary` `colortools::adjacent` etc.
- clean, web-friendly themes for ggplot2 and plotly
- a function to interact with [colorgorical](http://vrl.cs.brown.edu/color/)
- coefficient plots for fixed and random effects, plotting of GAM results.
## Installation
Install the development version directly from GitHub:
```{r install, eval=FALSE}
# install.packages("devtools")
devtools::install_github("m-clark/visibly")
```
Visibly is currently in its early stages, so more may be added soon. For some additional palettes for those fond of another time, you might be interested in [NineteenEightyR](https://github.com/m-clark/NineteenEightyR).
## Examples
Create a palette from a single starting point. This requires the <span class="pack">colortools</span> package to create equally spaced colors.
```{r example}
library(visibly)
create_palette('papayawhip')
```
Plot it to get a feel for things.
```{r plot}
create_palette('#ff5500', plot = T)
```
One of the built-in palettes is based on R's blue. Others are based on [Stan's](https://github.com/stan-dev/stan) red, [plotly's](https://github.com/ropensci/plotly) base colors, and the red-blue palette from [RColorBrewer](https://github.com/cran/RColorBrewer/blob/master/R/ColorBrewer.R).
A clean theme for <span class="pack">plotly</span>.
<!-- Plotly does all wonder of screwup here because size is so hard, so just export the png -->
```{r example4, eval=FALSE}
library(plotly)
mtcars %>%
plot_ly(x=~wt, y=~mpg, color=~cyl) %>%
add_markers(marker=list(size=15)) %>%
theme_plotly()
```
<img src="man/figures/plotly_wtf.png" style="display:block; margin: 0 auto;">
Visualize a correlation matrix via factor analysis.
```{r corrheat1, eval=FALSE}
data('bfi', package = 'visibly')
cor_matrix = cor(bfi, use='pair')
corr_heat(cor_matrix)
```
<img src='man/figures/corr_heat.png' style="display:block; margin: 0 auto;" width=50%>
<br>
<img src='man/figures/corr_heat_3d.png' style="display:block; margin: 0 auto;" width=50%>
Plot some model coefficients. Requires the <span class="pack">scico</span> package.
```{r lm0}
fit_lm = lm(mpg ~ ., mtcars)
plot_coefficients(fit_lm)
```
Plot GAM results
```{r gam}
library(mgcv)
d = gamSim()
gam_model = gam(y ~ x0 + s(x1) + s(x2, bs='gp') + s(x3, bs='ps'), data=d)
plot_gam(gam_model, main_var = x2)
plot_gam_check(gam_model)
```
See the [intro](https://m-clark.github.io/visibly/articles/intro.html) for more.