Skip to contents

Wrapper of make_strip_plot() that adds plotly interactivity.

NOTE: plotly has issues with overlapping axis labels when facetting (See this GitHub issue). The somewhat hacky solution to getting these plots to look good involves tweaking the panel_spacing arguments in ggplot2::theme().

If rendering from Mac OS, try setting the panel_spacing_x = 0.01 and panel_spacing_y = 3.

Usage

make_plotly(
  df,
  panel_spacing_x = 6,
  panel_spacing_y = 30,
  font_family = "Poppins",
  primary_color = washi::washi_pal[["standard"]][["red"]],
  secondary_color = washi::washi_pal[["standard"]][["ltgray"]],
  other_color = washi::washi_pal[["standard"]][["tan"]],
  primary_accent_color = washi::washi_pal[["standard"]][["blue"]]
)

Arguments

df

Dataframe containing columns: category, abbr_unit, unit, dummy, and sampleLabel.

panel_spacing_x, panel_spacing_y

Spacing between facet panels in units line when output = "html". Defaults to 6 for x and 30 for y for rendering in producer reports. These default values seem to look the best with the dimensions of the plot outputs in the reports. This argument is used to deal with plotly issues. See make_plotly() for examples.

font_family

Font family to use throughout plot. Defaults to "Poppins".

primary_color

Color of producer's sample points Defaults to WaSHI green.

secondary_color

Color of sample points with "Same crop" or "Same county" values in the category column. Defaults to WaSHI gray.

other_color

Color of sample points with "Other fields" value in category column. Defaults to WaSHI tan.

primary_accent_color

Color of facet strip background. Defaults to WaSHI blue.

Value

Facetted plotly strip plot.

Examples

# Read in wrangled plot data.
# See `data_wrangling.R` for processing steps.
path <- soils_example("dfPlot.csv")
df <- read.csv(
  path,
  encoding = "UTF-8"
)

# The data structure necessary to render the df triangle
dplyr::slice_sample(
  df,
  n = 1,
  by = category
) |>
  dplyr::glimpse()
#> Rows: 4
#> Columns: 23
#> $ year                  <int> 2023, 2023, 2022, 2023
#> $ dummy                 <chr> "dummy", "dummy", "dummy", "dummy"
#> $ category              <chr> "Other fields", "Same county", "Same crop", "You…
#> $ sampleLabel           <chr> "Result:", "County 9<br>Cereal Grain<br>Result:"…
#> $ sampleId              <chr> "23-AWK04-02", "23-DJU01-03", "22-RUX09-01", "23…
#> $ farmName              <chr> "Farm 138", "Farm 148", "Farm 092", "Farm 150"
#> $ producerName          <chr> "Muthanna", "Raashid", "Nika", "Shanna"
#> $ producerId            <chr> "AWK04", "DJU01", "RUX09", "WUY05"
#> $ fieldName             <chr> "Field 02", "Field 03", "Field 01", "Field 01"
#> $ fieldId               <int> 2, 3, 1, 1
#> $ county                <chr> "County 7", "County 9", "County 19", "County 9"
#> $ crop                  <chr> "Cereal Grain", "Cereal Grain", "Pasture, Seeded…
#> $ texture               <chr> "Loam", "Loamy Sand", "Sandy Loam", "Loamy Sand"
#> $ longitude             <int> -123, -120, -122, -119
#> $ latitude              <int> 47, 48, 49, 49
#> $ measurement           <chr> "wsa_%", "clay_%", "WHC_in.ft", "bd_g.cm3"
#> $ value                 <dbl> 90.50, 6.00, 1.44, 1.30
#> $ measurement_group     <chr> "physical", "physical", "physical", "physical"
#> $ order                 <int> 6, 3, 7, 5
#> $ measurement_full_name <chr> "Water Stable Aggregates", "Clay", "Water Holdin…
#> $ abbr                  <chr> "Agg. Stability", "Clay", "WHC", "Bulk Density"
#> $ unit                  <chr> "%", "%", "in/ft", "g/cm³"
#> $ abbr_unit             <chr> "Agg. Stability <br>(%)", "Clay <br>(%)", "WHC <…

# Make sure class of `category` is `ordered factor` with `Your fields`
# at the end so it is plotted on top of the other points.
df$category <- factor(
  df$category,
  levels = c(
    "Other fields",
    "Same county",
    "Same crop",
    "Your fields"
  ),
  ordered = TRUE
)

class(df$category)
#> [1] "ordered" "factor" 

levels(df$category)
#> [1] "Other fields" "Same county"  "Same crop"    "Your fields" 

# This `plotly` does not look right when viewing outside the reports
make_plotly(
  df,
  font_family = "sans"
)
# Conversely, this `plotly` looks better in this example when # the `panel_spacing` arguments are modified make_plotly( df, panel_spacing_x = 0.01, panel_spacing_y = 5, font_family = "sans" )