diff --git a/NEWS.md b/NEWS.md index cfbfe6b..d19b74f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,9 @@ # visibly 0.2 +## visibly 0.2.5 + +* Add plot_gam_3d. + ## visibly 0.2.4 * Add corr_heat. diff --git a/R/corr_heat.R b/R/corr_heat.R index 1183aa5..868eaab 100644 --- a/R/corr_heat.R +++ b/R/corr_heat.R @@ -242,7 +242,8 @@ corr_heat <- function(cormat, theme_plotly() # plotly gives a warning it can't do limits, then does them; this appears - # the only way to suppress + # the only way to suppress, but then won't work for Rmd html output; see + # issue #1202 suppressWarnings({ print(p) }) } else { diff --git a/README.Rmd b/README.Rmd index 19e40ec..a6a4ee4 100644 --- a/README.Rmd +++ b/README.Rmd @@ -62,23 +62,9 @@ Plot it to get a feel for things. create_palette('#ff5500', plot = T) ``` -There are some other options to express. - -```{r plot2} -create_palette('#ff5500', - alpha = .5, - plot = T, - name = 'orange_you_glad_you_have_this_color') -``` - - 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). -```{r rblue} -palettes$Rblue -``` - A clean theme for plotly. ```{r example4} @@ -89,14 +75,18 @@ mtcars %>% theme_plotly() ``` -Visualize a correlation matrix. +Visualize a correlation matrix via factor analysis. -```{r corrheat1} +```{r corrheat1, eval=FALSE} data('bfi', package = 'visibly') cor_matrix = cor(bfi, use='pair') corr_heat(cor_matrix) ``` + +
+ + Plot some model coefficients. Requires the scico package. diff --git a/README.md b/README.md index d4c3d3c..0ff8ba9 100644 --- a/README.md +++ b/README.md @@ -101,68 +101,12 @@ create_palette('#ff5500', plot = T) $tetradic [1] "#FF5500" "#AAFF00" "#00AAFF" "#5500FF" -There are some other options to express. - -``` r -create_palette('#ff5500', - alpha = .5, - plot = T, - name = 'orange_you_glad_you_have_this_color') -``` - - - - $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](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). -``` r -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" -``` - A clean theme for plotly. ``` r @@ -175,7 +119,7 @@ mtcars %>% -Visualize a correlation matrix. +Visualize a correlation matrix via factor analysis. ``` r data('bfi', package = 'visibly') @@ -183,7 +127,9 @@ cor_matrix = cor(bfi, use='pair') corr_heat(cor_matrix) ``` - + +
+ Plot some model coefficients. Requires the scico package. diff --git a/_pkgdown.yml b/_pkgdown.yml index b1cf503..46f337c 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -16,7 +16,7 @@ highlight: pygments home: - strip_header: true + #strip_header: true links: - text: Docs on Stats, R, and more href: http://m-clark.github.io @@ -58,6 +58,7 @@ reference: - plot_gam - plot_gam_check - plot_gam_2d + - plot_gam_3d - plot_gam_by figures: diff --git a/docs/articles/intro.html b/docs/articles/intro.html index 92c5e35..05b7aa1 100644 --- a/docs/articles/intro.html +++ b/docs/articles/intro.html @@ -94,7 +94,7 @@

An Introduction to Visibly

Michael Clark

-

2018-08-12

+

2018-08-16

Source: vignettes/intro.Rmd @@ -220,22 +220,23 @@

data('bfi', package = 'visibly')
 cor_matrix = cor(bfi, use='pair')
 corr_heat(cor_matrix)
-
-

The psych package is used to for the factor analysis, which is better suited to survey data and similar settings, where items are of the same type, and you can supply arguments to its fa function. The plot comes from plotly, and hovering over the squares provides the value.

+
+

The psych package is used to for the factor analysis, which is better suited to survey data and similar settings, where items are of the same type, and you can supply arguments to its fa function. The plot comes from plotly, and hovering over the squares provides the value.

corr_heat(cor_matrix, n_factors = 2, psych_opts = list(fm='ml', rot='oblimin'))
-
-

The color scheme is based on the previously mentioned scico package.

+
+

The color scheme is based on the previously mentioned scico package.

corr_heat(cor_matrix, pal = 'broc')
-
-

We can see that while there might be the usual ‘Big Five’ personality structure, it may also really just be two underlying constructs- neuroticism vs. the rest, at least for this sample.

+
+

We can see that while there might be the usual ‘Big Five’ personality structure, it may also really just be two underlying constructs- neuroticism vs. the rest, at least for this sample.

It occurred to me while updating this functionality that a 3-d approach might actually be useful here (it isn’t the vast majority of the time). When looking at the previous structure in 3-d, we probably would only think about two factors of items.

-
corr_heat(cor_matrix, three_d = TRUE, diagonal = NA)
-

-

Note that when you use it, the 3d visualization is interactive, so twist and tilt away!

-

There are multiple orderings available to help bring out the structure. This may be particularly useful if you are not dealing with measurement error type data.

-
corr_heat(cor(mtcars), three_d = TRUE, ordering = 'polar')
-

-

Who knew the mtcars data set could actually be interesting!

+
p = corr_heat(cor_matrix, three_d = TRUE, diagonal = NA)
+p
+
+

There are multiple orderings available to help bring out the structure. This may be particularly useful if you are not dealing with measurement error type data.

+
p = corr_heat(cor(mtcars), three_d = TRUE, ordering = 'polar')
+p
+
+

Who knew the mtcars data set could actually be interesting!

@@ -357,14 +358,20 @@

second_var = z, n_plot = 200)

-

A categorical moderator.

-
d = gamSim(4)
-Factor `by' variable example
-gam_model = gam(y ~ s(x2, fac, bs='fs'), data=d)
-
-plot_gam_by(gam_model,
-            main_var = x2,
-            by_var = fac)
+

In 3d.

+
plot_gam_3d(gam_model,
+            main_var = x,
+            second_var = z,
+            n_plot = 200)
+
+

A categorical moderator.

+
d = gamSim(4)
+Factor `by' variable example
+gam_model = gam(y ~ s(x2, fac, bs='fs'), data=d)
+
+plot_gam_by(gam_model,
+            main_var = x2,
+            by_var = fac)

diff --git a/docs/articles/intro_files/figure-html/gam-1.png b/docs/articles/intro_files/figure-html/gam-1.png index 5fa74b6..b6d0d6a 100644 Binary files a/docs/articles/intro_files/figure-html/gam-1.png and b/docs/articles/intro_files/figure-html/gam-1.png differ diff --git a/docs/articles/intro_files/figure-html/gam-2.png b/docs/articles/intro_files/figure-html/gam-2.png index c3cd857..5cdfee8 100644 Binary files a/docs/articles/intro_files/figure-html/gam-2.png and b/docs/articles/intro_files/figure-html/gam-2.png differ diff --git a/docs/articles/intro_files/figure-html/gam-3.png b/docs/articles/intro_files/figure-html/gam-3.png index 85ae62b..878cfba 100644 Binary files a/docs/articles/intro_files/figure-html/gam-3.png and b/docs/articles/intro_files/figure-html/gam-3.png differ diff --git a/docs/index.html b/docs/index.html index 2f5ddd7..f85b054 100644 --- a/docs/index.html +++ b/docs/index.html @@ -11,7 +11,7 @@ - + + + + + + + + +Plot 2d smooths in 3d — plot_gam_3d • visibly! + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + +
+ +

3d plot of 2d smooths for generalized additive models.

+ +
+ +
plot_gam_3d(model, main_var, second_var, conditional_data = NULL,
+  n_plot = 100, dmb = FALSE, ...)
+ +

Arguments

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
model

The mgcv gam model

main_var

The 'x' axis.

second_var

The 'y' axis'

conditional_data

Values for other covariates. Default is NULL see +details.

n_plot

Points to plot. 100 (the default) works well. Embiggen at the +cost of your own waiting time.

dmb

Whether to use plotly's display mode bar. Default is FALSE.

...

Arguments for scico

+ +

Value

+ +

A plotly surface object

+ +

Details

+ +

This works like plot_gam_2d, the only difference + being that a 3d plot is generated instead. It uses scico for + the palette. It is expected that the two input variables are continuous

+ +

See also

+ + + + +

Examples

+
library(mgcv); library(visibly) +set.seed(0) + +d = gamSim(2, scale=.1)$data
#> Bivariate smoothing example
mod <- gam(y ~ s(x, z), data = d) +plot_gam_3d(mod, main_var = x, second_var = z) +plot_gam_3d(mod, main_var = x, second_var = z, palette='tokyo')
+
+ +
+ + +
+ + + + + + diff --git a/docs/reference/plot_gam_check-1.png b/docs/reference/plot_gam_check-1.png index de6669c..ed2a149 100644 Binary files a/docs/reference/plot_gam_check-1.png and b/docs/reference/plot_gam_check-1.png differ diff --git a/docs/reference/plot_gam_check-2.png b/docs/reference/plot_gam_check-2.png index db78bc8..86d8efd 100644 Binary files a/docs/reference/plot_gam_check-2.png and b/docs/reference/plot_gam_check-2.png differ diff --git a/docs/reference/plot_gam_check.html b/docs/reference/plot_gam_check.html index c0bc336..c9001b8 100644 --- a/docs/reference/plot_gam_check.html +++ b/docs/reference/plot_gam_check.html @@ -183,7 +183,8 @@

See a plot_coefficients.lm, plot_coefficients.merMod, plot_coefficients, - plot_gam_2d, plot_gam

+ plot_gam_2d, plot_gam_3d, + plot_gam

Examples

diff --git a/man/figures/README-gam-1.png b/man/figures/README-gam-1.png index 941c460..be8154e 100644 Binary files a/man/figures/README-gam-1.png and b/man/figures/README-gam-1.png differ diff --git a/man/figures/README-gam-2.png b/man/figures/README-gam-2.png index 6984cc9..e2f9028 100644 Binary files a/man/figures/README-gam-2.png and b/man/figures/README-gam-2.png differ diff --git a/man/figures/corr_heat.png b/man/figures/corr_heat.png new file mode 100644 index 0000000..c888e7f Binary files /dev/null and b/man/figures/corr_heat.png differ diff --git a/man/figures/corr_heat_3d.png b/man/figures/corr_heat_3d.png new file mode 100644 index 0000000..eb5f751 Binary files /dev/null and b/man/figures/corr_heat_3d.png differ diff --git a/vignettes/intro.Rmd b/vignettes/intro.Rmd index 365f6ee..8bac503 100644 --- a/vignettes/intro.Rmd +++ b/vignettes/intro.Rmd @@ -154,22 +154,19 @@ We can see that while there might be the usual 'Big Five' personality structure, It occurred to me while updating this functionality that a 3-d approach might actually be useful here (it isn't the vast majority of the time). When looking at the previous structure in 3-d, we probably would only think about two factors of items. -```{r corrheat3d, dev='svglite'} -corr_heat(cor_matrix, three_d = TRUE, diagonal = NA) +```{r corrheat3d} +p = corr_heat(cor_matrix, three_d = TRUE, diagonal = NA) +p ``` - - -Note that when you use it, the 3d visualization is interactive, so twist and tilt away! There are multiple orderings available to help bring out the structure. This may be particularly useful if you are not dealing with measurement error type data. -```{r corrheat4, dev='svglite'} -corr_heat(cor(mtcars), three_d = TRUE, ordering = 'polar') +```{r corrheat4} +p = corr_heat(cor(mtcars), three_d = TRUE, ordering = 'polar') +p ``` - - Who knew the mtcars data set could actually be interesting! @@ -313,6 +310,17 @@ plot_gam_2d(gam_model, ``` +In 3d. + +```{r gam3d} +plot_gam_3d(gam_model, + main_var = x, + second_var = z, + n_plot = 200) +``` + + + A categorical moderator. ```{r gamby, echo=-1}