## ----setup, include=FALSE, cache=FALSE----------------------------------------
knitr::opts_chunk$set(
echo = TRUE,
message = FALSE,
warning = FALSE,
error = FALSE,
collapse = TRUE,
comment = NA,
R.options = list(width = 220),
dev.args = list(bg = 'transparent'),
dev = 'png',
fig.align = 'center',
out.width = '75%',
fig.asp = .75,
cache.rebuild = FALSE,
cache = FALSE
)
## ----example, echo=-(1:3)-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# bc r cmd build randomly decided margins were too large when they were okay
# before
par(mar=c(.5,.5,.5,.5))
library(visibly)
create_palette('papayawhip', plot = TRUE)
## ----example2-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
palettes$Rblue
## ----use1-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
pal = create_palette('#ff5500',
name = 'orange_you_glad_you_have_this_color')
library(ggplot2)
ggplot(mtcars, aes(x = wt, y = mpg)) +
geom_point(aes(color = factor(cyl)), size = 10, alpha = .5) +
scale_color_manual(values = pal$triadic) +
theme_clean()
## ----use2-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
library(dplyr)
mtcars %>%
mutate(cyl = factor(cyl)) %>%
tidyext::num_by(wt, cyl) %>%
ggplot(aes(x = cyl, y = Mean)) +
geom_col(aes(fill = cyl), width = .5, alpha = .85) +
scale_fill_manual(values = palettes$Rblue$triadic) +
theme_clean() +
theme(
legend.key.size = unit(.015, 'npc'),
axis.title.y = element_text(size = 20, hjust = -.05)
)
## ----colorgorical, eval=F-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# colorgorical(
# n = 6,
# pairPreference = 1,
# startPalette = list(c(10,-60, 45)),
# output = 'hex'
# )
## ----colorgorical-show, eval=T, echo=F------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
x = c(
"#002B00",
"#95C857",
"#334D37",
"#4EF185",
"#378811",
"#7FE7D3"
)
print(x)
qplot(
x = x,
y = 1:6,
color = I(x),
size = I(10)
)
## ----colorgorical2, eval=F------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# colorgorical(
# n = 10,
# perceptualDifference = .5,
# startPalette = list(c(10, -60, 45)),
# output = 'hex'
# )
## ----colorgorical2-show, eval=T, echo=F-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
x = c(
"#002B00",
"#D57381",
"#77CE3F",
"#DB0EAC",
"#2FF52B",
"#6C208E",
"#B1BF81",
"#4115F9",
"#518512",
"#B662CA"
)
print(x)
qplot(
x = x,
y = 1:10,
color = I(x),
size = I(10)
)
## ----col2lab--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
col2lab('dodgerblue')
## ----color_contrast_checker-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
color_contrast_checker(foreground = 'blue')
## ----color_contrast_checker2----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
color_contrast_checker(foreground = 'blue', background = 'black')
## ----color_contrast_checker3----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
iris %>%
ggplot(aes(Petal.Length, Petal.Width, color=Species)) +
geom_point()
scales::show_col(scales::hue_pal()(3))
color_contrast_checker(foreground = '#F8766D', background = 'gray92')
color_contrast_checker(foreground = '#00BA38', background = 'gray92')
color_contrast_checker(foreground = '#619CFF', background = 'gray92')
## ----corrheat1------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
data('bfi', package = 'visibly')
cor_matrix = cor(bfi, use='pair')
corr_heat(cor_matrix)
## ----corrheat2------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
corr_heat(cor_matrix,
n_factors = 2,
psych_opts = list(fm = 'ml', rot = 'oblimin'))
## ----corrheat3------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
corr_heat(cor_matrix, pal = 'broc')
## ----corrheat3d-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
p = corr_heat(cor_matrix, three_d = TRUE, diagonal = NA)
p
## ----corrheat4------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
p = corr_heat(cor(mtcars), three_d = TRUE, ordering = 'polar')
p
## ----lm0------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
fit_lm = lm(mpg ~ ., mtcars)
plot_coefficients(fit_lm)
## ----lm1------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
fit_lm = lm(mpg ~ ., mtcars)
plot_coefficients(
fit_lm,
palette = 'oslo',
order = 'decreasing',
sd_multi = 1,
keep_intercept = TRUE,
ref_line = c(-1:1)
)
## ----data-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
plot_coefficients(fit_lm, plot = FALSE)
## ----fe1------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
library(lme4)
fit_mer = lmer(Reaction ~ Days + (Days|Subject), sleepstudy)
plot_coefficients(fit_mer)
## ----re1------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
plot_coefficients(fit_mer, ranef = TRUE, which_ranef = 'Subject')
## ----fe2------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
fit_mer2 = lmer(count ~ zAge + zBase * Trt +
(1 | patient),
data = brms::epilepsy)
plot_coefficients(fit_mer2,
palette = 'berlin')
## ----re_patchwork---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
plots = plot_coefficients(fit_mer, ranef = TRUE, which_ranef = 'Subject')
library(patchwork)
plots[[1]] + plots[[2]]
## ----fe_brms1, eval=FALSE-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# library(brms)
#
# fit_brms_two = brm(count ~ zAge + zBase * Trt +
# (1 | patient) + (1 | obs),
# data = epilepsy,
# family = poisson)
#
# plot_coefficients(fit_brms_two)
## ----fe_brms1_vis, echo = FALSE-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
load('../tests/testthat/brms_res.RData')
plot_coefficients(fit_brms_two)
## ----re_brms1-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
plot_coefficients(fit_brms_two, ranef = TRUE, which_ranef = 'patient') +
theme(axis.text.x = element_text(angle = -90))
## ----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(gam_model,
main_var = vars(x1, x2, x3),
ncol = 1,
line_color = palettes$Rblue$Rblue,
ribbon_color = palettes$Rblue$complementary[2])
plot_gam_check(gam_model)
## ----gam2d, echo=-1-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
set.seed(1234)
d = gamSim(2, scale = .1)$data
gam_model = gam(y ~ s(x, z, bs='gp'), data=d)
plot_gam_2d(gam_model,
main_var = x,
second_var = z,
n_plot = 200)
## ----gam3d----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
plot_gam_3d(gam_model,
main_var = x,
second_var = z,
n_plot = 200)
## ----gamby, echo=-1-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
set.seed(1234)
d = gamSim(4)
gam_model = gam(y ~ s(x2, fac, bs='fs'), data=d)
plot_gam_by(gam_model,
main_var = x2,
by_var = fac)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.