diff --git a/docs/articles/colour.html b/docs/articles/colour.html index 362bf94e..433f3eae 100644 --- a/docs/articles/colour.html +++ b/docs/articles/colour.html @@ -167,16 +167,16 @@

#> # A tibble: 539 x 10 #> carat cut color clarity depth table price x y z #> <dbl> <ord> <ord> <ord> <dbl> <dbl> <int> <dbl> <dbl> <dbl> -#> 1 0.76 Ideal I SI1 61.8 57 2399 5.89 5.83 3.62 -#> 2 0.39 Premium G VS1 61.7 62 951 4.69 4.65 2.88 -#> 3 0.4 Ideal E SI1 60.5 57 737 4.77 4.81 2.9 -#> 4 1.3 Very Good I VS1 62.1 59 7333 6.97 7.01 4.34 -#> 5 1.62 Good I VS1 59.6 65 9526 7.69 7.59 4.55 -#> 6 0.42 Ideal D VS1 61.4 55 1006 4.8 4.9 2.98 -#> 7 1.06 Very Good D SI1 59.4 57 5713 6.65 6.72 3.97 -#> 8 1.21 Premium G VS2 62.2 58 7996 6.85 6.81 4.25 -#> 9 0.7 Ideal F VVS2 61.5 56 4439 5.7 5.78 3.53 -#> 10 0.9 Good I SI1 63.5 59 3176 6.05 6.1 3.86 +#> 1 1.1 Very Good F VVS1 62.2 59 10329 6.56 6.69 4.12 +#> 2 0.36 Ideal F IF 60.3 57 1063 4.61 4.65 2.79 +#> 3 0.73 Fair J VS1 64.6 60 1802 5.68 5.59 3.64 +#> 4 0.5 Very Good D VS2 60.1 63 1712 5.13 5.09 3.07 +#> 5 0.9 Good H VVS1 63.8 59 4847 6.09 6.13 3.9 +#> 6 0.4 Ideal E SI1 62.4 54 694 4.72 4.74 2.95 +#> 7 0.51 Ideal G VVS1 60.5 59 1893 5.16 5.19 3.13 +#> 8 0.71 Very Good J SI1 59.1 61 1861 5.82 5.85 3.45 +#> 9 1.07 Premium D VS2 62.4 57 7550 6.59 6.51 4.09 +#> 10 1.07 Premium F SI2 58.2 58 4319 6.79 6.72 3.93 #> # … with 529 more rows gg_point_col(plot_data, diff --git a/docs/articles/colour_files/figure-html/unnamed-chunk-5-1.png b/docs/articles/colour_files/figure-html/unnamed-chunk-5-1.png index 7217ecde..b61b2cbb 100644 Binary files a/docs/articles/colour_files/figure-html/unnamed-chunk-5-1.png and b/docs/articles/colour_files/figure-html/unnamed-chunk-5-1.png differ diff --git a/docs/articles/colour_files/figure-html/unnamed-chunk-6-1.png b/docs/articles/colour_files/figure-html/unnamed-chunk-6-1.png index 574ead08..140e1abf 100644 Binary files a/docs/articles/colour_files/figure-html/unnamed-chunk-6-1.png and b/docs/articles/colour_files/figure-html/unnamed-chunk-6-1.png differ diff --git a/docs/articles/ggplotly.html b/docs/articles/ggplotly.html index af5f9528..bc6d8245 100644 --- a/docs/articles/ggplotly.html +++ b/docs/articles/ggplotly.html @@ -142,8 +142,20 @@

font_family = "Helvetica") plotly::ggplotly(plot) -
- +
+ + +
+

+Turning off widgets other than the camera

+

The plotly_camera function turns off all widgets other than the camera to make a cleaner graph.

+
plot <- gg_point_col(penguins, bill_length_mm, body_mass_g, species,
+                     font_family = "Helvetica")
+
+plotly::ggplotly(plot) %>%
+  plotly_camera()
+
+

@@ -151,7 +163,7 @@

Use mutate_text, text_var and plotly::ggplotly(tooltip = "text") to make pretty tooltips.

A variable can be added to the text_var in the gg_* function. This variable is then used in the ggplotly tooltip when tooltip = text is added to the ggplotly function.

simplevis provides a mutate_text function which can produce a variable that is a string or variable names and values for a tooltip. Note this function converts column names to sentence case using the snakecase::to_sentence_case function.

-
+
 plot_data <- penguins %>%
   mutate_text()
 
@@ -161,9 +173,9 @@ 

plotly::ggplotly(plot, tooltip = "text") %>% plotly_camera()

-
-

The mutate_text function uses all variables in the dataset by defalut, but a subset can be used if desired.

-
plot_data <- penguins %>%
+
+

The mutate_text function uses all variables in the dataset by defalut, but a subset can be used if desired.

+
plot_data <- penguins %>%
   mutate_text(c("species", "flipper_length_mm"))
 
 plot <- gg_point_col(plot_data, bill_length_mm, body_mass_g, species,
@@ -172,37 +184,32 @@ 

plotly::ggplotly(plot, tooltip = "text") %>% plotly_camera()

-
- -
-
-

-Turning off widgets other than the camera

-

The plotly_camera function turns off all widgets other than the camera to make a cleaner graph.

+
+

Controlling the colour legend.

Sometimes the ggplotly legend displays elements in a different order to how you want them. You can reverse them or specify a specific order using plotly_col_legend. Note, this only affects the legend elements.

-
plot_data <- dplyr::sample_frac(ggplot2::diamonds, 0.05)
+
plot_data <- dplyr::sample_frac(ggplot2::diamonds, 0.05)
 
 plot <- gg_point_col(plot_data, carat, price, color,
                      font_family = "Helvetica")
 
 plotly::ggplotly(plot)
-
- +
+ plotly::ggplotly(plot) %>% plotly_col_legend(rev = TRUE) -
- +
+

sf maps

sf ggplots can also be converted to interactive ggplotly objects using the same method.

-
plot_data <- example_sf_point %>%
+
plot_data <- example_sf_point %>%
   mutate_text()
 
 plot <- gg_sf_col(plot_data, trend_category,
@@ -213,8 +220,8 @@ 

plotly::ggplotly(plot, tooltip = "text") %>% plotly_camera()

-
-
col_cuts <- as.vector(quantile(example_sf_point$median, probs = c(0, 0.25, 0.5, 0.75, 1)))
+
+
col_cuts <- as.vector(quantile(example_sf_point$median, probs = c(0, 0.25, 0.5, 0.75, 1)))
 
 plot_data <- example_sf_point %>%
   mutate(quartile = case_when(median < col_cuts[2] ~ "Q1",
@@ -230,8 +237,8 @@ 

plotly::ggplotly(plot, tooltip = "text") %>% plotly_camera()

-
- +
+
diff --git a/docs/articles/leaflet.html b/docs/articles/leaflet.html index ca5cabd5..1e33d38e 100644 --- a/docs/articles/leaflet.html +++ b/docs/articles/leaflet.html @@ -121,8 +121,7 @@

2021-06-04

-
library(tidyverse)
-library(simplevis)
+
library(simplevis)

Overview

@@ -140,61 +139,61 @@

col_method = "quantile", col_cuts = seq(0, 1, 0.25), title = "Monitored medians, 2008-17")

-
-
leaflet_sf_col(example_sf_polygon, density,
+
+
leaflet_sf_col(example_sf_polygon, density,
      col_method = "bin",
      col_cuts = c(0, 10, 50, 100, 150, 200, Inf),
      col_labels_dp = 0,
      title = "Modelled density, 2017")
-
-

The popup will default to a leafpop::popupTable of all variables, but can be adjusted to a subset using the popup_vars_vctr argument.

+
+

The popup will default to a leafpop::popupTable of all variables, but can be adjusted to a subset using the popup_vars_vctr argument.

leaflet_sf_col(example_sf_point, trend_category, popup_vars_vctr = c("site_id", "median"))
-
-

The tooltip will default to the colour variable, but can be adjusted using the text_var variable.

+
+

The tooltip will default to the colour variable, but can be adjusted using the text_var variable.

leaflet_sf_col(example_sf_point, trend_category, text_var = site_id)
-
- +
+

Basemaps

Users have a basemap argument that defaults to “light” but has other options.

leaflet_sf(example_sf_point, basemap = "dark")
-
-
leaflet_sf(example_sf_point, basemap = "satellite")
-
-
leaflet_sf(example_sf_point, basemap = "street")
-
- +
+
leaflet_sf(example_sf_point, basemap = "satellite")
+
+
leaflet_sf(example_sf_point, basemap = "street")
+
+ +
+
+

+Adding additional layers

+

As a leaflet object is produced, you can add additional layers with leaflet.

+
leaflet_sf_col(example_sf_point,
+               col_var = trend_category,
+               pal = c("#0D94A3", "#C4C4C7", "#AE4E51")) %>%
+  leaflet::addPolygons(data = nz, color = "#35B779", weight = 3, fillOpacity = 0, opacity = 1)
+
+

shiny

A leaflet basemap is available for use in shiny apps. It defaults to the top layer being “light”.

-
simplevis::leaflet_basemap()
-
-

You can set the bounds by adding a vector or bbox of bounds.

-
leaflet_basemap(bounds = c(166.70047,-34.45676, 178.52966,-47.06345))
-
- +
simplevis::leaflet_basemap()
+
+

You can set the bounds by adding a vector or bbox of bounds.

+
leaflet_basemap(bounds = c(166.70047,-34.45676, 178.52966,-47.06345))
+
+ bb % sf::st_bbox() -simplevis::leaflet_basemap(bounds = bb) -
- -
-
-

-Adding additional layers

-

As a leaflet object is produced, you can add additional layers with leaflet.

-
leaflet_sf_col(example_sf_point,
-               col_var = trend_category,
-               pal = c("#0D94A3", "#C4C4C7", "#AE4E51")) %>%
-  leaflet::addPolygons(data = nz, color = "#35B779", weight = 3, fillOpacity = 0, opacity = 1)
-
- +leaflet_basemap(bounds = bb) +
+

diff --git a/docs/articles/scales.html b/docs/articles/scales.html index 51ee758c..a0b53c54 100644 --- a/docs/articles/scales.html +++ b/docs/articles/scales.html @@ -222,7 +222,7 @@

Colour scales

-

Customise the colour title. Note that because colour labels will be converted by default in simplevis, but we can turn this default transformation off using ggplot2::waiver()

+

Customise the colour title. Note that because colour labels will be converted to sentence case by default in simplevis, but we can turn this off when we do not want this to occur using ggplot2::waiver()

plot_data <- ggplot2::diamonds %>%
   group_by(cut, clarity) %>%
   summarise(average_price = mean(price))
diff --git a/docs/articles/shiny.html b/docs/articles/shiny.html
index fc6b6b08..f2b76721 100644
--- a/docs/articles/shiny.html
+++ b/docs/articles/shiny.html
@@ -116,8 +116,9 @@ 

2021-06-04

-
library(tidyverse)
-library(simplevis)
+
library(dplyr)
+library(simplevis)
+library(palmerpenguins)

Overview

@@ -127,12 +128,8 @@

Working with quoted inputs

In shiny it is often easier to work with quoted variables. For ggplot wrapper function, wrap the variables in !!sym, as shown below.

-
plot_data <- ggplot2::diamonds %>%
-  sample_frac(0.05) %>%
-  mutate(cut = stringr::str_to_sentence(cut))
-
-gg_point_col_facet(plot_data, !!sym("carat"), !!sym("price"), !!sym("color"), !!sym("cut"))
-

+
gg_point_col(penguins, !!sym("bill_length_mm"), !!sym("body_mass_g"), !!sym("species"))
+

@@ -147,54 +144,28 @@

  • font sizes need to be appropriate
  • simplevis provides mobile support for plots through a mobile argument, which makes the above changes.

    -
    plot_data <- ggplot2::diamonds %>%
    -  mutate(cut = stringr::str_to_sentence(cut)) %>%
    -  group_by(cut) %>%
    -  summarise(average_price = mean(price))
    -
    -gg_hbar(plot_data, average_price, cut,
    -            title = "Average diamond price by cut",
    -            x_title = "Average price ($US)",
    -            y_title = "Cut",
    -            mobile = TRUE)
    -

    -

    The default font size scales to look about right when viewed on a mobile device.

    -

    Build one app that:

    -
      -
    • identifies a input$isMobile value of whether a user is on a mobile device or not through a mobileDetect function in the ui.R and some javascript in the www/js/mobile.js -
    • -
    • in the server.R, generate a reactive plot object incorporating an mobile = input$isMobile argument into simplevis ggplot function
    • -
    • in the server.R, render a plot object and a plotly object
    • -
    • in the ui.R, use conditional panels to provide the rendered plotly object to non-mobile users and the rendered plot object to mobile users
    • -
    -

    The reason why a plotly object is not provided to mobile users is that ggplotly does not implement all aspects of ggplot. This makes it hard to make it work nicely every time. A more reliable approach is to just provide a ggplot object instead to those users.

    +
    plot_data <- storms %>%
    +  group_by(year, status) %>%
    +  summarise(wind = mean(wind))
    +
    +gg_point_col(penguins, bill_length_mm, body_mass_g, species, mobile = T)
    +

    +

    From the simplevis templates, the mobileDetect function in the ui.R and associated javascript in the www/js/mobile.js returns a TRUE or FALSE input$isMobile value if the user is on a mobile device.

    +

    This input$isMobile TRUE or FALSE value can then be added to the mobile argument in the simplevis gg_* function in the server.R.

    +

    One reliable way to ensure the plot viewed by mobile users is in the ui.R to use conditional panels to provide a plotly object to non-mobile users and a plot object to mobile users.

    +

    This method is implemented in the simplevis templates.

    App templates

    -

    This method is demonstrated in two template apps that are provided called template1 and template2.

    -

    Users can access these functions by using the run_template functions for the applicable app, and then clicking on the download_code button to access a zip file of the code.

    -

    You can use these either to understand the method outlined above or to use as templates.

    +

    Users can access the simplevis functions by using the run_template functions for the applicable app, and then clicking on the download_code button to access a zip file of the code.

    run_template("template1") # a graph and table
     run_template("template2") # a leaflet map, as well as graph and table
    -

    If you use these as templates, the basic method to create an app is:

    -
      -
    • run run_template("template1") or run_template("template2") and download the code to use as a template
    • -
    • In get_data.R, extract, process and save your data into the data subfolder, including a zip file for download
    • -
    • In make_app_vis.R, draft your visualisations with dummy character inputs
    • -
    • In global.R, read your data in, and create any vectors required
    • -
    • In ui.R, add a app title
    • -
    • In ui.R. add radioButtons and other widgets
    • -
    • In server.R, add code within reactive plot_data and plot components, change any dummy character inputs to shiny user inputs. Add a mobile = input$isMobile specification to any simplevis graphs if you are looking to support mobile users as well as desktop
    • -
    • In server.R, add code for map and table components, as applicable
    • -
    • In www/About.Rmd, update as necessary
    • -
    • If using google tag-manager, obtain a tag and replace GTM-XXXXXXX with it in the www/js/tag-manager-js file.
    • -

    Thanks!

    -

    Thanks to Gervasio Marchand for creating the code to identify whether users are on a mobile device as described here: https://g3rv4.com/2017/08/shiny-detect-mobile-browsers

    +

    Thanks to Gervasio Marchand for creating the code to identify whether users are on a mobile device as described here

    diff --git a/docs/articles/shiny_files/figure-html/unnamed-chunk-3-1.png b/docs/articles/shiny_files/figure-html/unnamed-chunk-3-1.png index 0de0313d..3dc3b574 100644 Binary files a/docs/articles/shiny_files/figure-html/unnamed-chunk-3-1.png and b/docs/articles/shiny_files/figure-html/unnamed-chunk-3-1.png differ diff --git a/docs/articles/shiny_files/figure-html/unnamed-chunk-4-1.png b/docs/articles/shiny_files/figure-html/unnamed-chunk-4-1.png index 0a67b452..183f6776 100644 Binary files a/docs/articles/shiny_files/figure-html/unnamed-chunk-4-1.png and b/docs/articles/shiny_files/figure-html/unnamed-chunk-4-1.png differ diff --git a/docs/articles/simplevis.html b/docs/articles/simplevis.html index 65eba363..6e81aa5c 100644 --- a/docs/articles/simplevis.html +++ b/docs/articles/simplevis.html @@ -280,8 +280,8 @@

    Simplevis also provides leaflet and leaflet_sf functions, which work in a similar way.

    leaflet_sf_col(example_sf_point, trend_category,
               pal = c("#4575B4", "#D3D3D3", "#D73027"))
    -
    - +
    +

    @@ -298,8 +298,8 @@

    "sf", "sf", NA, NA, "Categorical or numeric", "Categorical", "Identity", ) %>% DT::datatable()

    -
    -