diff --git a/_pkgdown.yml b/_pkgdown.yml
new file mode 100644
index 0000000..097b1ee
--- /dev/null
+++ b/_pkgdown.yml
@@ -0,0 +1,77 @@
+title: visibly!
+title-img: logo.png
+
+authors:
+ Michael Clark:
+ href: https://m-clark.github.io
+ html: Michael Clark
+
+template:
+ params:
+ highlight: pygments
+ #bootswatch: sandstone
+ templates_path: inst/pkgdown
+
+highlight: pygments
+
+
+home:
+ links:
+ - text: Docs on Stats, R, and more
+ href: http://m-clark.github.io
+
+reference:
+ - title: "Dealing with color"
+ desc: >
+ Functions for getting and creating palettes.
+ contents:
+ - create_palette
+ - palettes
+ - colorgorical
+ - col2lab
+
+ - title: "Themes"
+ desc: >
+ Clean themes.
+ contents:
+ - theme_trueMinimal
+ - theme_plotly
+ - theme_blank
+
+ - title: "Plotting model results"
+ desc: >
+ Functions for plotting fixed and random effect coefficients and more.
+ contents:
+ - plot_coefficients
+ - plot_coefficients.brmsfit
+ - plot_coefficients.lm
+ - plot_coefficients.merMod
+
+figures:
+ dev: png
+ dpi: 96
+ dev.args: []
+ fig.ext: png
+ fig.width: 7.2916667
+ fig.height: ~
+ fig.retina: 2
+ fig.asp: 1.618
+
+navbar:
+ title: "whatever bc pkgdown will ignore it"
+ type: ~
+ left:
+ - text: "Reference"
+ href: "reference/index.html"
+ - text: "News"
+ href: "news/index.html"
+ - text: Articles
+ menu:
+ - text: Introduction to visibly
+ href: articles/intro.html
+ right:
+ - icon: fa-github-alt
+ href: https://github.com/m-clark
+ - icon: fa-empire
+ href: https://m-clark.github.io
+
diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html
new file mode 100644
index 0000000..5bb3aba
--- /dev/null
+++ b/docs/LICENSE-text.html
@@ -0,0 +1,139 @@
+
+
+
+
YEAR: 2018 +COPYRIGHT HOLDER: Michael Clark ++ +
vignettes/intro.Rmd
+ intro.Rmd
One can get started by creating a palette. This uses the colortools package to provide evenly spaced colors.
+ +$papayawhip
+[1] "papayawhip"
+
+$complementary
+[1] "#FFEFD5" "#D5E5FF"
+
+$analogous
+[1] "#FFEFD5" "#FAFFD5" "#FFDAD5"
+
+$split_complentary
+[1] "#FFEFD5" "#D5FAFF" "#DAD5FF"
+
+$triadic
+[1] "#FFEFD5" "#D5FFEF" "#EFD5FF"
+
+$square
+[1] "#FFEFD5" "#D5FFDA" "#D5E5FF" "#FFD5FA"
+
+$tetradic
+[1] "#FFEFD5" "#E5FFD5" "#D5E5FF" "#EFD5FF"
+Here is a palette based on the blue in the R logo.
+palettes$Rblue
+$Rblue
+[1] "#1f65b7"
+
+$complementary
+[1] "#1f65b7" "#b7701f"
+
+$monochromatic
+[1] "#1f65b7" "#366caa" "#4a719e" "#5a7491"
+
+$analogous
+[1] "#1f65b7" "#241fb7" "#1fb2b7"
+
+$split_complementary
+[1] "#1f65b7" "#b2b71f" "#b7241f"
+
+$triadic
+[1] "#1f65b7" "#66b71f" "#b71f66"
+
+$tetradic
+[1] "#1f65b7" "#b7701f" "#66b71f" "#701fb7"
The palette creator can create some decent categorical distinctions without too much fuss. The following also demonstrates one of the themes, which has no grid/gray, and de-bolds the black font while leaving text clear; even the fainter version will pass web standards for contrast against a white background. As shown, you can still fiddle with the theme beyond that.
+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_trueMinimal()
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_trueMinimal() +
+ theme(legend.key.size = unit(.015, 'npc'),
+ axis.title.y = element_text(size=20, hjust=-.05))
Another way to create palettes is with a function that works with colorgorical. It connects to that website to create colors based on things like whether they perceptually go together aesthetically, whether they are more or less perceptually distinct, or even if their name is unique.
+## colorgorical(n=6, pairPreference = 1, startPalette = list(c(10, -60, 45)), output = 'hex')
+[1] "#002B00" "#95C857" "#334D37" "#4EF185" "#378811" "#7FE7D3"
## colorgorical(n=10, perceptualDifference = .5, startPalette = list(c(10, -60, 45)), output = 'hex')
+ [1] "#002B00" "#D57381" "#77CE3F" "#DB0EAC" "#2FF52B" "#6C208E" "#B1BF81" "#4115F9" "#518512" "#B662CA"
To get a starting palette from an R or hexadecimal value, try col2lab.
+ +However, if you want palettes that are colorblind-safe, print-safe etc., especially for continuous scales, you should use packages like viridis and scico.
+I have some visualizations for plotting uncertainty intervals for fixed and random effects of mixed models. These require the scico package, as well as lme4 and brms which are used to do the mixed models in the first place.
+I don’t really use them aside for demonstration, but in this case the lm and glm objects served as a baseline.
+ +Change the palette, order and more.
+fit_lm = lm(mpg ~ ., mtcars)
+plot_coefficients(fit_lm,
+ palette='oslo',
+ order = 'decreasing',
+ sd_multi = 1,
+ keep_intercept = TRUE,
+ ref_line = c(-1:1))
You may want to do your own visualization, or go beyond the default settings. Rather than providing a couple dozen arguments for you to tweak, just so you can still feel like you can’t get it just quite right. Here’s the data, do with it what you will!
+plot_coefficients(fit_lm, plot=FALSE)
+ Coefficient value ui_l ui_u
+1 am 2.52022689 -1.59307422 6.63352799
+2 qsec 0.82104075 -0.64064884 2.28273034
+3 drat 0.78711097 -2.48363516 4.05785711
+4 gear 0.65541302 -2.33110691 3.64193294
+5 vs 0.31776281 -3.89125440 4.52678003
+6 disp 0.01333524 -0.02237976 0.04905024
+7 hp -0.02148212 -0.06501928 0.02205504
+8 cyl -0.11144048 -2.20148720 1.97860625
+9 carb -0.19941925 -1.85692425 1.45808574
+10 wt -3.71530393 -7.50413253 0.07352467
I do a lot of mixed models, which is my main reason for providing this functionality, so I’ve started to create some ways to plot the results of the separate fixed and random effects. We’ll use lme4.
+library(lme4)
+fit_mer = lmer(Reaction ~ Days + (Days|Subject), sleepstudy)
+plot_coefficients(fit_mer)
And now the random effects. Fewer options can be found here, but this is intentional as you’d want them ordered and the fixed effect style would make things messy whenever there are many random effects, which is often the case. With multiple random effects, a list of ggplot objects is returned.
+ +
+$Days
+Now for a different palette. Again, these only apply to fixed effects visualizations, due to the number of categories typically seen with random effects and how the visualization is created.
+fit_mer2 = lmer(count ~ log_Age_c + log_Base4_c * Trt +
+ (1 | patient),
+ data = brms::epilepsy)
+plot_coefficients(fit_mer2,
+ palette = 'lajolla')
You can use patchwork to put them into one graph.
+plots = plot_coefficients(fit_mer, ranef = TRUE, which_ranef = 'Subject')
+
+library(patchwork)
+
+plots[[1]] + plots[[2]]
I like brms quite a bit and use it a lot. It served as the motivation for these coefficient plots, as did bayesplot, and tidyposterior.
+library(brms)
+fit_brms = brm(count ~ log_Age_c + log_Base4_c * Trt +
+ (1 | patient) + (1 | obs),
+ data = epilepsy,
+ family = poisson)
+plot_coefficients(fit_brms)
And now the random effects.
+plot_coefficients(fit1, ranef = TRUE, which_ranef = 'patient') +
+ theme(axis.text.x = element_text(angle = -90))
Visibly is a handful of functions I use for color palettes, themes, etc. in R. Inside you will find:
+colortools::complementary
colortools::adjacent
etc.The development version then install directly from GitHub:
+ +Visibly is currently in its very early stages, so more may be added soon. For some additional palettes for those fond of another time, you might be interested in NineteenEightyR.
+Create a palette. This requires the colortools
package to create equally spaced colors.
library(visibly)
+create_palette('papayawhip')
+$papayawhip
+[1] "papayawhip"
+
+$complementary
+[1] "#FFEFD5" "#D5E5FF"
+
+$analogous
+[1] "#FFEFD5" "#FAFFD5" "#FFDAD5"
+
+$split_complentary
+[1] "#FFEFD5" "#D5FAFF" "#DAD5FF"
+
+$triadic
+[1] "#FFEFD5" "#D5FFEF" "#EFD5FF"
+
+$square
+[1] "#FFEFD5" "#D5FFDA" "#D5E5FF" "#FFD5FA"
+
+$tetradic
+[1] "#FFEFD5" "#E5FFD5" "#D5E5FF" "#EFD5FF"
Plot it to get a feel for things.
+ +$`#ff5500`
+[1] "#ff5500"
+
+$complementary
+[1] "#FF5500" "#00AAFF"
+
+$analogous
+[1] "#FF5500" "#FFD500" "#FF002B"
+
+$split_complentary
+[1] "#FF5500" "#00FFD4" "#002BFF"
+
+$triadic
+[1] "#FF5500" "#00FF55" "#5500FF"
+
+$square
+[1] "#FF5500" "#2AFF00" "#00AAFF" "#D500FF"
+
+$tetradic
+[1] "#FF5500" "#AAFF00" "#00AAFF" "#5500FF"
+There are some other options to express.
+ +$orange_you_glad_you_have_this_color
+[1] "#FF550080"
+
+$complementary
+[1] "#FF550080" "#00AAFF80"
+
+$analogous
+[1] "#FF550080" "#FFD50080" "#FF002B80"
+
+$split_complentary
+[1] "#FF550080" "#00FFD480" "#002BFF80"
+
+$triadic
+[1] "#FF550080" "#00FF5580" "#5500FF80"
+
+$square
+[1] "#FF550080" "#2AFF0080" "#00AAFF80" "#D500FF80"
+
+$tetradic
+[1] "#FF550080" "#AAFF0080" "#00AAFF80" "#5500FF80"
+One of the built-in palettes is based on R’s blue. Others are based on Stan’s red, plotly’s base colors, and the red-blue palette from RColorBrewer.
+palettes$Rblue
+$Rblue
+[1] "#1f65b7"
+
+$complementary
+[1] "#1f65b7" "#b7701f"
+
+$monochromatic
+[1] "#1f65b7" "#366caa" "#4a719e" "#5a7491"
+
+$analogous
+[1] "#1f65b7" "#241fb7" "#1fb2b7"
+
+$split_complementary
+[1] "#1f65b7" "#b2b71f" "#b7241f"
+
+$triadic
+[1] "#1f65b7" "#66b71f" "#b71f66"
+
+$tetradic
+[1] "#1f65b7" "#b7701f" "#66b71f" "#701fb7"
One can create some colors from colorgorical.
+## colorgorical(n=6, pairPreference = 1, startPalette = list(c(10, -60, 45)), output = 'hex')
+[1] "#002B00" "#95C857" "#334D37" "#4EF185" "#378811" "#7FE7D3"
Pretty, and pretty easy, coefficient plots.
+ +NEWS.md
+ Converts an R color
+ +col2lab(color)+ +
color | +An R color or a hexadecimal string of the form "#rrggbb" |
+
---|
A matrix of LAB values useful for colorgorical starting points.
+ +See the help for convertColor.
+ ++library(visibly) +col2lab('red')#> L a.x b +#> [1,] 53.48418 80.01027 67.38407x = list('red', 'white', 'blue') +col2lab(x)#> L a.x b +#> [1,] 53.48418 80.01027 67.38407 +#> [2,] 100.00000 0.00000 0.00000 +#> [3,] 32.24075 78.82042 -107.93632+
An interface for creating palettes from + colorgorical.
+ +colorgorical(n = 10, perceptualDifference = 0, nameDifference = 0, + nameUniqueness = 0, pairPreference = 0, hueFilters = list(), + lightnessRange = c("25", "85"), startPalette = list(), output = "HEX")+ +
n | +Number of color values to return. |
+
---|---|
perceptualDifference | +Value from 0 to 1. See details. |
+
nameDifference | +Value from 0 to 1. See details. |
+
nameUniqueness | +Value from 0 to 1. See details. |
+
pairPreference | +Value from 0 to 1. See details. |
+
hueFilters | +Must be given as an element of a list. See details. |
+
lightnessRange | +See details. |
+
startPalette | +A starting point for the color as a vector of 3 CIE Lab +values. Must be given as an element of a list. See details. |
+
output | +Character string. Output may be given as LAB, sRGB, or HEX +values. If 'LAB' or 'sRGB', a matrix of those values where each row +represents a color. If 'HEX', the default, a character vector of hex values +is returned. |
+
A character vector of color values in hex form.
+ +This function accesses the colorgorical website to create a color
+ palette. It requires two other packages to work: httr
and
+ jsonlite
, and if you want a hex value, colorspace
.
The following are relevant parts from the descriptions at the website.
+Perceptual Distance: Increasing Perceptual Distance favors palette + colors that are more easily discriminable to the human eye. To accurately + model human color acuity, this is performed using CIEDE2000 in CIE Lab + color space.
+Name Difference: Increasing Name Difference favors palette colors + that share few common names. This is similar to perceptual distance, but + can lead to different results in certain areas of color space. This happens + when there are many different names for perceptually close colors (e.g., + red and pink are perceptually close but named differently). Colorgorical + calculates this using Heer and Stone's Name Difference function, which is + built on top of the XKCD color-name survey.
+Pair Preference: Increasing Pair Preference favors palette colors + that are, on average, predicted to be more aesthetically preferable + together. Typically these colors are similar in hue, have different + lightness, and are cooler colors (blues and greens). Pair Preference is + based off of Schloss and Palmer's research on color preference.
+Name Uniqueness: Increasing Name Uniqueness favors palette colors + that are uniquely named. Some colors like red are readily named and are + favored, whereas other colors are less obviously named and are ignored. + Like, Name Difference, Name Uniqueness is based on Heer and Stone's + color-name research.
+Select hue filter: You can limit which colors are selected by either + dragging over the wheel to select a hue range, or by entering the angles + manually (e.g., select only reds). You can also make multiple selections + after one another to select many different hue ranges (e.g., select both + greens and purples).
+Select lightness range: You can change whether Colorgorical samples + lighter or darker colors.
+Add starting colors: You can guarantee that certain colors are in + your palette. Note, as near as I can tell, it is only guaranteed if you + have already created a palette at the website and start with one of the + generated colors. Otherwise, it appears to pick something close to the + starting point(s) given the settings. See the example.
+NOTE: Because JSON is being used behind the scenes, for hueFilters
+ and startPalette
, the values must be given as a list.
For example:
+hueFilters = list(c(90, 180))
startPalette = list(c(59, 62, 70))
The R code is based on the gist by Kamil Slowikowski found here: +link.
+ +Original Python source code +at GitHub.
+ + +# NOT RUN { +library(visibly) +colorgorical(n=12, pairPreference = 1, startPalette = list(c(10, -60, 45))) + +# go from hex to lab to use single starting point, but see note about +starting colors +col = t(col2rgb(palettes$Rblue$Rblue)) +col = convertColor(col, from = "sRGB", to = "Lab", scale.in = 255)[1,] +testcol = colorgorical(n=12, pairPreference = 1, startPalette = list(col)) +testcol = c(palettes$Rblue$Rblue, testcol) +ggplot2::qplot(x=factor(testcol, levels = testcol), + y=1:12, + color=I(testcol), + size=I(10)) +# } +++
Uses colortools package (and possibly scales) to easily create a + color palette based on a initial input color.
+ +create_palette(colorhex, name = NULL, toHCL = FALSE, plot = FALSE, + alpha = 1)+ +
colorhex | +Hexadecimal value of color or an R color name. |
+
---|---|
name | +optional name of color |
+
toHCL | +Convert colors to hcl. Defaults to |
+
plot | +Plot the results. Defaults to |
+
alpha | +Transparency. Takes values from 0 to 1. Default is 1. |
+
A list of colors
+ +Will return complementary, analogous/adjacent, split complementary, + triadic, square and tetradic color values relative to the initial color. + Note that if you want sequential, qualitative, diverging etc., other + packages like + RColorBrewer, + colorspace, and + colortools will + do that for you.
+ + ++library(visibly) +create_palette(colorhex = '#ff5500', name='orange')#> $orange +#> [1] "#ff5500" +#> +#> $complementary +#> [1] "#FF5500" "#00AAFF" +#> +#> $analogous +#> [1] "#FF5500" "#FFD500" "#FF002B" +#> +#> $split_complentary +#> [1] "#FF5500" "#00FFD4" "#002BFF" +#> +#> $triadic +#> [1] "#FF5500" "#00FF55" "#5500FF" +#> +#> $square +#> [1] "#FF5500" "#2AFF00" "#00AAFF" "#D500FF" +#> +#> $tetradic +#> [1] "#FF5500" "#AAFF00" "#00AAFF" "#5500FF" +#>create_palette(colorhex = '#ff5500', name='orange', alpha=.5)#> $orange +#> [1] "#FF550080" +#> +#> $complementary +#> [1] "#FF550080" "#00AAFF80" +#> +#> $analogous +#> [1] "#FF550080" "#FFD50080" "#FF002B80" +#> +#> $split_complentary +#> [1] "#FF550080" "#00FFD480" "#002BFF80" +#> +#> $triadic +#> [1] "#FF550080" "#00FF5580" "#5500FF80" +#> +#> $square +#> [1] "#FF550080" "#2AFF0080" "#00AAFF80" "#D500FF80" +#> +#> $tetradic +#> [1] "#FF550080" "#AAFF0080" "#00AAFF80" "#5500FF80" +#>+
A list of commonly used palettes with some base color and including +complementary, monochromatic, analogous, split_complementary, triadic, +tetradic. Otherwise, just ones I use e.g. colorbrewer, plotly or others of +interest.
+ +palettes
+
+ (Possibly) named vectors/lists of colors
+- orange : #ff5500
+- stanred: #b2001d
+- RdBu_11: RdBu palette from colorbrewer for sequence of 11
+- Rblue: #1f65b7
+- Latvian Red: #9E1B34
+- Tyrian Purple: #3c6602
+- Tyrian Purple2: #990024 A more web friendly version
+- Plotly: plotly's default colorscale, because decent documentation is next +to impossible for those folks. +...
+ +For example the colortools and colorspace packages, http://paletton.com/, https://www.sessions.edu/color-calculator/, https://colorbrewer.org
+ +https://stackoverflow.com/questions/40673490/how-to-get-plotly-js-default-colors-list
+ + +R/plot_coefficients.brmsfit.R
+ plot_coefficients.brmsfit.Rd
Plot fixed or random effects coefficients for brmsfit objects.
+ +# S3 method for brmsfit +plot_coefficients(model, order = "decreasing", + sd_multi = 2, keep_intercept = FALSE, palette = "bilbao", + ref_line = 0, trans = NULL, plot = TRUE, ranef = FALSE, + which_ranef = NULL, ...)+ +
model | +The model that is the point of this function. For example, lm, glm, gam, lme4, brms. |
+
---|---|
order | +The order of the plots- "increasing", "decreasing", or a numeric +vector giving the order. The default is NULL, i.e. the default ordering. Not applied to random effects. |
+
sd_multi | +The multiplier that determines the width of the interval. Default is 2. |
+
keep_intercept | +Default is FALSE. Intercepts are typically on a very +different scale than covariate effects. |
+
palette | +A scico palette. Default is 'bilbao'. |
+
ref_line | +A reference line. Default is zero. |
+
trans | +A transformation function to be applied to the coefficients +(e.g. exponentiation). |
+
plot | +Default is TRUE, but sometimes you just want the data. |
+
ranef | +If applicable, whether to plot random effects instead of fixed effects. |
+
which_ranef | +If plotting random effects, which one to plot. |
+
... | +Other arguments applied for specific methods. |
+
A ggplot of the coefficients and their interval estimates. Or the + data that would be used to create the plot.
+ + ++# placeholder + +
A basic plot of coefficients with their uncertainty interval.
+ +plot_coefficients(model, order = "decreasing", sd_multi = 2, + keep_intercept = FALSE, palette = "bilbao", ref_line = 0, + trans = NULL, plot = TRUE, ranef = FALSE, which_ranef = NULL, ...)+ +
model | +The model that is the point of this function. For example, lm, glm, gam, lme4, brms. |
+
---|---|
order | +The order of the plots- "increasing", "decreasing", or a numeric +vector giving the order. The default is NULL, i.e. the default ordering. Not applied to random effects. |
+
sd_multi | +The multiplier that determines the width of the interval. Default is 2. |
+
keep_intercept | +Default is FALSE. Intercepts are typically on a very +different scale than covariate effects. |
+
palette | +A scico palette. Default is 'bilbao'. |
+
ref_line | +A reference line. Default is zero. |
+
trans | +A transformation function to be applied to the coefficients +(e.g. exponentiation). |
+
plot | +Default is TRUE, but sometimes you just want the data. |
+
ranef | +If applicable, whether to plot random effects instead of fixed effects. |
+
which_ranef | +If plotting random effects, which one to plot. |
+
... | +Other arguments applied for specific methods. |
+
A ggplot of the coefficients and their interval estimates. Or the + data that would be used to create the plot.
+ + ++mod = lm(mpg ~ ., mtcars) +plot_coefficients(mod, order = 'increasing')+
R/plot_coefficients.lm.R
+ plot_coefficients.lm.Rd
A basic plot of coefficients with their uncertainty interval for + lm and glm objects.
+ +# S3 method for lm +plot_coefficients(model, order = "decreasing", sd_multi = 2, + keep_intercept = FALSE, palette = "bilbao", ref_line = 0, + trans = NULL, plot = TRUE, ...) + +# S3 method for glm +plot_coefficients(model, order = "decreasing", sd_multi = 2, + keep_intercept = FALSE, palette = "bilbao", ref_line = 0, + trans = NULL, plot = TRUE, ...)+ +
model | +The lm or glm model |
+
---|---|
order | +The order of the plots- "increasing", "decreasing", or a numeric +vector giving the order. The default is NULL, i.e. the default ordering. Not applied to random effects. |
+
sd_multi | +The multiplier that determines the width of the interval. Default is 2. |
+
keep_intercept | +Default is FALSE. Intercepts are typically on a very +different scale than covariate effects. |
+
palette | +A scico palette. Default is 'bilbao'. |
+
ref_line | +A reference line. Default is zero. |
+
trans | +A transformation function to be applied to the coefficients +(e.g. exponentiation). |
+
plot | +Default is TRUE, but sometimes you just want the data. |
+
... | +Other arguments applied for specific methods. |
+
A ggplot of the coefficients and their interval estimates. Or the + data that would be used to create the plot.
+ +This is more or less a function that serves as the basis for other models I actually use.
+ + +++
R/plot_coefficients.merMod.R
+ plot_coefficients.merMod.Rd
Plot fixed or random effects coefficients for merMod objects.
+ +# S3 method for merMod +plot_coefficients(model, order = "decreasing", + sd_multi = 2, keep_intercept = FALSE, palette = "bilbao", + ref_line = 0, trans = NULL, plot = TRUE, ranef = FALSE, + which_ranef = NULL, ...)+ +
model | +The model that is the point of this function. For example, lm, glm, gam, lme4, brms. |
+
---|---|
order | +The order of the plots- "increasing", "decreasing", or a numeric +vector giving the order. The default is NULL, i.e. the default ordering. Not applied to random effects. |
+
sd_multi | +The multiplier that determines the width of the interval. Default is 2. |
+
keep_intercept | +Default is FALSE. Intercepts are typically on a very +different scale than covariate effects. |
+
palette | +A scico palette. Default is 'bilbao'. |
+
ref_line | +A reference line. Default is zero. |
+
trans | +A transformation function to be applied to the coefficients +(e.g. exponentiation). |
+
plot | +Default is TRUE, but sometimes you just want the data. |
+
ranef | +If applicable, whether to plot random effects instead of fixed effects. |
+
which_ranef | +If plotting random effects, which one to plot. |
+
... | +Other arguments applied for specific methods. |
+
A ggplot of the coefficients and their interval estimates. Or the + data that would be used to create the plot.
+ +This plots the fixed or random effects of lme4 objects. For more
+ information on the fixed effects, see plot_coefficients.It
+ requires the lme4 package. The plot for random effects is
+ basically the dotplot demonstrated at ?lme4::ranef
, but instead uses
+ ggplot2 so you would have a little easier time working with
+ it to do with as you wish (for multiple random effects, a list of ggplot
+ objects can be returned). Many of the options for fixed effects are
+ removed, as they either don't make much sense or for practical reasons.
+library(lme4) +fit_mer = lmer(Reaction ~ Days + (Days|Subject), sleepstudy) +plot_coefficients(fit_mer, ranef = TRUE, which_ranef = 'Subject')#> $`(Intercept)`#> +#> $Days#>
This isn't really meant to be directly called, but is instead + internally used by the plot_coefficients function.
+ +plot_coefs(model_input, palette, ref_line, trans)+ +
model_input | +Processed model effects |
+
---|---|
palette | +A scico palette. Default is 'bilbao'. |
+
ref_line | +A reference line. Default is zero. |
+
trans | +A transformation function to be applied to the coefficients +(e.g. exponentiation). |
+
A ggplot of the coefficients with their corresponding uncertainty + bars.
+ + +This isn't really meant to be directly called, but is instead + internally used by the plot_coefficients function.
+ +plot_fixefs(model, order = "decreasing", sd_multi = 2, + keep_intercept = FALSE, palette = "bilbao", ref_line = 0, + trans = NULL, plot = TRUE, ...) + +# S3 method for brmsfit +plot_fixefs(model, order, sd_multi, keep_intercept, palette, + ref_line, trans, plot, ...) + +# S3 method for merMod +plot_fixefs(model, order, sd_multi, keep_intercept, palette, + ref_line, trans, plot, ...)+ +
model | +The model that is the point of this function. For example, lm, glm, gam, lme4, brms. |
+
---|---|
order | +The order of the plots- "increasing", "decreasing", or a numeric +vector giving the order. The default is NULL, i.e. the default ordering. Not applied to random effects. |
+
sd_multi | +The multiplier that determines the width of the interval. Default is 2. |
+
keep_intercept | +Default is FALSE. Intercepts are typically on a very +different scale than covariate effects. |
+
palette | +A scico palette. Default is 'bilbao'. |
+
ref_line | +A reference line. Default is zero. |
+
trans | +A transformation function to be applied to the coefficients +(e.g. exponentiation). |
+
plot | +Default is TRUE, but sometimes you just want the data. |
+
... | +Other arguments applied for specific methods. |
+
a ggplot2 object or the effect estimates
+ +plot_coefficients
+#placeholder +
This isn't really meant to be directly called, but is instead + internally used by the plot_coefficients function.
+ +plot_ranefs(model, sd_multi = 2, ref_line = 0, trans = NULL, + plot = TRUE, which_ranef = NULL, ...) + +# S3 method for brmsfit +plot_ranefs(model, sd_multi, ref_line, trans, plot, + which_ranef, ...) + +# S3 method for merMod +plot_ranefs(model, sd_multi, ref_line, trans, plot, + which_ranef, ...)+ +
model | +The brmsfit or lme4 model |
+
---|---|
sd_multi | +The sd multiplier |
+
ref_line | +The reference line |
+
trans | +A transformation to be applied to the coefficient. Currently unused. |
+
plot | +Whether to plot or just provide the data. |
+
which_ranef | +Which random effect to plot |
+
... | +Other options passed to specific methods. Currently unused. |
+
a ggplot2 object or the effect estimates
+ +brmsfit
:
merMod
:
plot_coefficients
+#placeholder +
Clean up plots from their defaults.
+ +theme_trueMinimal() + +theme_plotly(vis, MB = FALSE) + +theme_blank(vis, MB = FALSE)+ +
vis | ++ |
---|---|
MB | +For plotly, an option to display the mode bar. Defaults to FALSE. |
+
From a gray background, to unnecessary gridlines, to by-default + reference lines, some of the more popular visualization packages come out + 75 + remove unnecessary gridlines, 'de-bold' the blacks, etc.
+- **ggplot2**: theme_trueMinimal
This function takes a ggplot object
+ and removes the gray background, gridlines and adds opacity to the default
+ black axes and labels, allowing the pattern of the visual to be expressed
+ in unimpeded fashion.
- **plotly**: theme_plotly
, theme_blank
removes reference
+ lines at zero, and some of its 'modebar' is unnecessary. Otherwise little
+ is changed at this point, except for theme_blank, which is like theme_void
+ for ggplot.
You may continue to override any aspect of these themes. For example with +ggplot2, you would just add a theme afterward just like you would any other +plot.
+ + ++library(visibly) +library(ggplot2) + +data(mtcars) + +ggplot(aes(wt, mpg), data=mtcars) + + geom_point() + + labs(title='Plot') + + theme_trueMinimal()#>+#> +#>#>+#> +#>