Templates

Text

Quarto specific

Cross formatting

```{md}
#, fig.height=9}
#| label: fig-meancheck
#| warning: false
#| echo: false
#| eval: false
```
```{md}
::: {.panel-tabset}

## tab 1

## tab 2

:::
```

See: Some placed in <https://docs.zettlr.com/en/core/snippets/>

```{md}
:::: {#fig-hersh41 layout-ncol="2"}

Where A is placesd

Where b is placed

(a left): A screen and (b right) a derivation 
::::
```

-or-

```{md}
:::: columns
::: {.column}
Content of column 1
:::

::: {.column}
Content of column 2
:::
::::
```

-or-

```{md}
:::{.grid}
:::{.g-col-6}

:::
:::{.g-col-6}

:::

:::
```

Also worth peaking at https://www.andreashandel.com/posts/2023-06-13-custom-callouts-quarto/ & https://quarto.org/docs/authoring/callouts.html

```{md}
::: {.callout-note  collapse="false"}
## This would be a callout title

Note that there are five types of callouts, including:
`note`, `warning`, `important`, `tip`, and `caution`.
:::
```
```{html}
<details>
<summary> What points were used?</summary>
I am collapsed
</details>
```
```{md}
::: {.content-hidden}

Will not appear in HTML.

:::
```

Notes

See also: a (WIP) Data Driven Workflow

```{md}
home                      <- landing page
├── tutorial              <- landing page
│   └── part 1            <- landing page
├── how-to guides         <- landing page
│   ├── install
│   └── deploy
├── reference             <- landing page
│   ├── commandline tool
│   └── available endpoints
└── explanation           <- landing page
    ├── best practice recommendations
    └── performance
Paper
├── Introduction
├── Background       <- literature_notes,reference,explanation
├── Methods          <- how-to guides,reference,explanation 
├── Results
├── Discussion       <- reference,explanation 
└── Conclutions    
```

see also: installing Zotero

A literature note header and some form of a content prompt like so:

```{md}
---
title: "<paper title>"
id: 
keywords:
  - Drone
  - lo_q-med_q-hi_q
...
[citation]
# Summary
## Mine
## MaxF
## TFIDF
# Annotations
<From top sticky note>
## What was the question, problem or purpose of the study?
## What methods are deployed?
### What data did they use?
### What noteable codebase/tools were developed/deployed?
## What are the authors’ major findings/conclusions?
## What evidence supports their interpretations?
## Why are the findings of this research important?
## Explicit next steps they suggest
## Did I find anything surprising?
## What am I confused about?
## Interesting figures?
## Promising References
```
```{md}
---
title: "Title"
id: YYYYMMDDmmss
keywords:
  - fill
  - these
  - in
...
```

Functions

See also: Packaging and Production

```{r}
funfunc <- function(path_to_inputs,path_to_outputs,overwrite=FALSE,is_verbose=FALSE) {
  # sinew::moga(file.path(getwd(),"R/funfunc.R",fsep = .Platform$file.sep),overwrite = TRUE)
  # devtools::document()
  # pkgdown::build_site(new_process=TRUE)
  #
  # devtools::load_all()
  
  #///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  # ----- User inputs --------------------------------------------------------------------------------------------
  #///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  fn_time_start <- Sys.time()
  
  #///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  # ----- Step function ------------------------------------------------------------------------------------------
  # More verbose description as needed
  # Can be multiple lines
  #///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  if(is_verbose) {
    runtime <- Sys.time() - fn_time_start
    units(runtime) <- "hours"
    print(paste("Total Compute Time: ",round(runtime, digits = 3),"hours"))
  }
  
  return(TRUE)
}
```
```{python}
import argparse
import geopandas
import contextily
import os
import sys
import time
import datetime

def main(is_verbose):
    """
    Subset dam lines from hydrofabric
    Args:
        data_path (str): The path to hydrofabric data.
        hf_id (str): A hydrofabric flowpath id to use as the headwater.
        is_verbose (bool): Whether to print verbose output.
        
    Example usage:
    python /hydrofabric3D/Python/subset_dam_lines.py \
        -data_path "/media/sf_G_DRIVE/data/" \
        -hf_id 'wb-2414833' \
        -v

    flowpaths, transects, xyz = subset\_dam\_lines(data\_path = "/media/sf\_G\_DRIVE/data/", hf\_id = 'wb-2414833', is\_verbose = True)

    """
    start_runtime = time.time()

    if is_verbose:
        end_runtime = time.time()
        time_passed = (end_runtime - start_runtime) // 1
        time_passed = datetime.timedelta(seconds=time_passed)
        print('Total Compute Time: ' + str(time_passed))

    return True

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description="Subset dam break lines.")
    parser.add_argument("data_path", help="The path to hydrofabric data.")
    parser.add_argument("hf_id", type=str, help="A hydrofabric flowpath id to use as the headwater.")
    parser.add_argument("-v", "--verbose", action="store_true", help="Enable verbose output.")

    args = parser.parse_args()

    processed_result = subset_dam_lines(args.data_path, args.hf_id, args.verbose)
```

QR code helpers

The share page on the more tools ellipse.

Via the qrcode package (tips):

```{r}
qrcode::add_logo(
  qrcode::qr_code("https://www.reddit.com/media?url=https%3A%2F%2Fi.redd.it%2Fdvsax6nc9mmc1.jpeg", ecl = "H"),
  file.path("_temp",fsep = .Platform$file.sep),
  ecl = "L",
  hjust = "c",
  vjust = "c"
)
```

In quarto’s terminal: quarto install extension jmbuhr/quarto-qrcode
Shortcode:

Tabled data flow

toy_table = tibble::tribble(
  ~Attribute, ~Description, ~Table,
  "id","A table specific id, otherwise meaningless","RRASSLER_hull.fgb, model_footprints.fgb, XS.fgb",
  "geometry","Simple Features Geometry (LINESTRING or POLYGON)","RRASSLER_hull.fgb, RRASSLER_river.fgb, model_footprints.fgb",
  "master_id","A database specific ID for a cross section","XS.fgb",
  "start_master_id","The starting 'master_id' from the cross section database for that model","model_footprints.fgb",
)
toy_table <- data.frame(x  = c( 10,  15,  20,  25,  30.0,  40.0),
                        m  = c(105, 103, 102, 101, 100.5, 100.0),
                        sd = c(125, 113, 108, 105, 103.5, 101.5))

The tablesGenerator helper

toy_table <- 
"| Unit | Time to open | Time to conflate |
|------|--------------|------------------|
| 06   |              | 0.168            |
| 03   | 2.228        | 1.63             |
| 02   | 1.902        | 1.515            |
| 05   | 1.795        | 2.738            |"
toy_table <- readr::read_delim(toy_table, delim = '|',show_col_types = FALSE,name_repair = 'unique_quiet') |> dplyr::select(-1, -last_col()) |> dplyr::slice(-1)
Warning: The `file` argument of `read_delim()` should use `I()` for literal data as of
readr 2.2.0.
  
  # Bad (for example):
  read_csv("x,y\n1,2")
  
  # Good:
  read_csv(I("x,y\n1,2"))
glossarycsv <- data.table::fread("./glossary.csv")

As demo’d in NHD

# toy_table_string <- paste(capture.output(dput(toy_table)), collapse = "\n")
toy_table_string <-"structure(list(unit = c(\"HUC 2\", \"HUC 6\", \"HUC 8\", \"HUC 12\"), \n    term = c(\"Regions\", \"Basins\", \"Subbasins\", \"Subwatersheds\"\n    ), n_elements = c(22L, 404L, 2400L, 102992L), area_m2 = structure(c(498880342456.806, \n    27058155606.7937, 4554789527.12941, 106139261.933943), units = structure(list(\n        numerator = c(\"m\", \"m\"), denominator = character(0)), class = \"symbolic_units\"), class = \"units\"), \n    area_num = c(498880342456.806, 27058155606.7937, 4554789527.12941, \n    106139261.933943), printed_size = c(\"498880342456.806 m^2\", \n    \"27058155606.7937 m^2\", \"4554789527.12941 m^2\", \"106139261.933943 m^2\"\n    ), landsat_count = structure(c(16629344748.5602, 901938520.226455, \n    151826317.57098, 3537975.39779809), units = structure(list(\n        numerator = character(0), denominator = character(0)), class = \"symbolic_units\"), class = \"units\"), \n    modis_count = structure(c(997760684.913613, 54116311.2135873, \n    9109579.05425881, 212278.523867885), units = structure(list(\n        numerator = character(0), denominator = character(0)), class = \"symbolic_units\"), class = \"units\"), \n    k_count = structure(c(498880342.456806, 27058155.6067937, \n    4554789.52712941, 106139.261933943), units = structure(list(\n        numerator = character(0), denominator = character(0)), class = \"symbolic_units\"), class = \"units\")), row.names = c(NA, \n4L), class = \"data.frame\")"
toy_table <- eval(parse(text = toy_table_string))

report_table <- toy_table |> 
  dplyr::rename('Area (m2)' = area_num,
                'Area (km2)' = k_count,
                'LANDSAT cells (30 m2)' = landsat_count,
                'MODIS cells (500 m2)' = modis_count,
                'Number of features' = n_elements)

report_table[ , !(names(report_table) %in% c("printed_size","area_m2"))]
    unit          term Number of features    Area (m2) LANDSAT cells (30 m2)
1  HUC 2       Regions                 22 498880342457           16629344749
2  HUC 6        Basins                404  27058155607             901938520
3  HUC 8     Subbasins               2400   4554789527             151826318
4 HUC 12 Subwatersheds             102992    106139262               3537975
  MODIS cells (500 m2)  Area (km2)
1          997760684.9 498880342.5
2           54116311.2  27058155.6
3            9109579.1   4554789.5
4             212278.5    106139.3

Visuals

See the docs

formattable::formattable(toy_table)
Things I hate Numbers Tables
Lists computers Politicians
Speling errors mixed types 20.1
Repitition Repitition 0.25

See the docs

knitr::kable(toy_table, format = "markdown")
Things I hate Numbers Tables
Lists computers Politicians
Speling errors mixed types 20.1
Repitition Repitition 0.25

See the Kable and KableExtra

kableExtra::kable(toy_table) %>% kableExtra::kable_styling(latex_options = "striped")
Things I hate Numbers Tables
Lists computers Politicians
Speling errors mixed types 20.1
Repitition Repitition 0.25

See the docs

DT::datatable(toy_table,caption = "Table",filter = "top")

See the docs

reactable::reactable(toy_table,filterable = TRUE,searchable = TRUE)
toy_table
# A tibble: 3 × 3
  ` Things I hate  ` ` Numbers `           ` Tables `      
  <chr>              <chr>                 <chr>           
1 " Lists          " " computers       "   " Politicians  "
2 " Speling errors " " mixed types       " " 20.1   "      
3 " Repitition     " " Repitition       "  " 0.25   "      

The tablesGenerator helper

Things I hate Numbers Tables
Lists computers Politicians
Speling errors mixed types 20.1
Repitition Repitition 0.25

See the docs

gt::gt(toy_table)
Things I hate Numbers Tables
Lists computers Politicians
Speling errors mixed types 20.1
Repitition Repitition 0.25

Exporting

```{r}
#// Setup
#///////////////////////////////////////////////////////////////////////////////////////////////////////
base_width_in <- 10
base_title_size_pt <- 14
base_subtitle_size_pt <- 10
base_general_text_size_pt <- 12
get_aspect_ratio <- function(plot) {
  # Build the plot and extract the aspect ratio from the coordinate system
  p_build <- ggplot2::ggplot_build(plot); aspect_ratio <- p_build$layout$coord$aspect(p_build$layout$panel_params[[1]])
  
  # coord_sf returns NULL if the ratio is 1, so we'll default to 1
  if (is.null(aspect_ratio)) { return(1) } else { return(aspect_ratio) }
}

#// Each round
#///////////////////////////////////////////////////////////////////////////////////////////////////////
# export_plot <- basemaps::basemap_ggplot(CONUS_ext,map_service = "osm", map_type = "streets") +
  ggplot2::theme(text = ggplot2::element_text(family = "Helvetica", size = base_general_text_size_pt),
                 plot.title = ggplot2::element_text(size = base_title_size_pt, hjust = 0.5),
                 plot.subtitle = ggplot2::element_text(family = "mono", size = base_subtitle_size_pt, hjust = 0.5))

#// And Export
#///////////////////////////////////////////////////////
target_width_in <- 2 # I've designed these for a full page but want to stuff them into a 2  colum so 10 / 

plot_aspect_ratio <- get_aspect_ratio(export_plot)
scale_factor <- target_width_in / base_width_in
target_height_in <- target_width_in / plot_aspect_ratio

ggplot2::ggsave(filename = "_osm_streets_bm230.jpg", plot = 
                  
  export_plot +
    ggplot2::theme(
      text = ggplot2::element_text(size = base_general_text_size_pt * scale_factor),
      plot.title = ggplot2::element_text(size = base_title_size_pt * scale_factor),
      plot.subtitle = ggplot2::element_text(size = base_subtitle_size_pt * scale_factor)
    )
    
  ,path = file.path(temp_path,"sizefuck",fsep = .Platform$file.sep),
  width = target_width_in,height = target_height_in, units = "in", dpi=300)
knitr::plot_crop("./_bm_carto_voyage_ul.jpg")
#///////////////////////////////////////////////////////////////////////////////////////////////////////
```
```{r}
#// Setup
#///////////////////////////////////////////////////////////////////////////////////////////////////////
base_width_px <- 1920
base_height_px <- 1080
base_title_size_pt <- 14
base_subtitle_size_pt <- 10
base_general_text_size_pt <- 12
get_aspect_ratio <- function(plot) {
  # Build the plot and extract the aspect ratio from the coordinate system
  p_build <- ggplot2::ggplot_build(plot)
  aspect_ratio <- p_build$layout$coord$aspect(p_build$layout$panel_params[[1]])
  
  # coord_sf returns NULL if the ratio is 1, so we'll default to 1
  if (is.null(aspect_ratio)) { return(1) } else { return(aspect_ratio) }
}

#// Each round
#///////////////////////////////////////////////////////////////////////////////////////////////////////
# export_plot <- basemaps::basemap_ggplot(CONUS_ext,map_service = "carto", map_type = "voyager_labels_under") +
  ggplot2::labs(title = "Carto - Voyager under labels", subtitle = 'basemaps::basemap_ggplot(CONUS_ext,map_service = "carto", map_type = "voyager_labels_under")') +
  ggplot2::theme_void() +
  ggplot2::theme(text = ggplot2::element_text(family = "Helvetica", size = base_general_text_size_pt),
                 plot.title = ggplot2::element_text(size = base_title_size_pt, hjust = 0.5),
                 plot.subtitle = ggplot2::element_text(family = "mono", size = base_subtitle_size_pt, hjust = 0.5))

#// And Export
#///////////////////////////////////////////////////////
target_width_px <- 1920   # This is the full screen width in pixels

plot_aspect_ratio <- get_aspect_ratio(export_plot)
scale_factor <- target_width_px / base_width_px
target_height_px <- target_width_px / plot_aspect_ratio
ggplot2::ggsave(filename = "_bm_carto_voyage_ul.jpg", plot = 
                  
  export_plot +
    ggplot2::theme(
      text = ggplot2::element_text(size = base_general_text_size_pt * scale_factor),
      plot.title = ggplot2::element_text(size = base_title_size_pt * scale_factor),
      plot.subtitle = ggplot2::element_text(size = base_subtitle_size_pt * scale_factor)
    )
  
  ,path = ".",
  width = target_width_px, height = target_height_px, units = "px", dpi = 300)
knitr::plot_crop("./_bm_carto_voyage_ul.jpg")
#///////////////////////////////////////////////////////////////////////////////////////////////////////
```

From FINNSTATS

```{r}
p +
  ggplot2::theme(
    panel.background = ggplot2::element_rect(fill='transparent'), #transparent panel bg
    plot.background = ggplot2::element_rect(fill='transparent', color=NA), #transparent plot bg
    panel.grid.major = ggplot2::element_blank(), #remove major gridlines
    panel.grid.minor = ggplot2::element_blank(), #remove minor gridlines
    legend.background = ggplot2::element_rect(fill='transparent'), #transparent legend bg
    legend.box.background = ggplot2::element_rect(fill='transparent') #transparent legend panel
  )
```

Make sure to indicate that the backdrop should be translucent when exporting the plot with ggsave().

```{r}
ggplot2::ggsave('myplot.png', p, bg='transparent')
```
```{r}
#// Image control setup
#///////////////////////////////////////////////////////////////////////////////////////////////////////
presentation_prepend <- '_testdeck'
base_width_px <- 1920
base_height_px <- 1080
base_title_size_pt <- 14
base_subtitle_size_pt <- 10
base_general_text_size_pt <- 12
get_aspect_ratio <- function(plot) {
  # Build the plot and extract the aspect ratio from the coordinate system
  p_build <- ggplot2::ggplot_build(plot)
  aspect_ratio <- p_build$layout$coord$aspect(p_build$layout$panel_params[[1]])
  
  # coord_sf returns NULL if the ratio is 1, so we'll default to 1
  if (is.null(aspect_ratio)) { return(1) } else { return(aspect_ratio) }
}
#///////////////////////////////////////////////////////////////////////////////////////////////////////
```

And for a chunck

```{r}
#// And Export
#///////////////////////////////////////////////////////
filename <- paste0(presentation_prepend,"_stepimage.jpg")
target_width_px <- 1920

if(!file.exists(filename)) {

    #//////////////////////////////////////////////////////////
    existing_plot <- basemaps::basemap_ggplot(CONUS_ext,map_service = "carto", map_type = "voyager_labels_under") +
      ggplot2::labs(title = "Carto - Voyager under labels", subtitle = 'basemaps::basemap_ggplot(CONUS_ext,map_service = "carto", map_type = "voyager_labels_under")') +
      ggplot2::theme_void() +
      ggplot2::theme(text = ggplot2::element_text(family = "Helvetica", size = base_general_text_size_pt),
                     plot.title = ggplot2::element_text(size = base_title_size_pt, hjust = 0.5),
                     plot.subtitle = ggplot2::element_text(family = "mono", size = base_subtitle_size_pt, hjust = 0.5))
    #existing_plot
    #/////////////////////////////////////////////////////////

    plot_aspect_ratio <- get_aspect_ratio(existing_plot)
    scale_factor <- target_width_px / base_width_px
    target_height_px <- target_width_px / plot_aspect_ratio
    ggplot2::ggsave(filename = filename, plot = 
                      
                      existing_plot +
                      ggplot2::theme(
                        text = ggplot2::element_text(size = base_general_text_size_pt * scale_factor),
                        plot.title = ggplot2::element_text(size = base_title_size_pt * scale_factor),
                        plot.subtitle = ggplot2::element_text(size = base_subtitle_size_pt * scale_factor)
                      )
                    
                    ,path = ".",
                    width = target_width_px, height = target_height_px, units = "px", dpi = 300)
    knitr::plot_crop(filename)
}
#///////////////////////////////////////////////////////////////////////////////////////////////////////
```

![](r filename){.absolute left="7%" bottom="0%" height="90%"}

https://r-graph-gallery.com/159-save-interactive-streamgraph-to-static-image-png.html

Page sizing

Powerpoint

  • Standard Landscape
    • Full page: 13.333 in x 7.5 in | 338.7 mm x 190.5 mm (16:9)
    • 960 x 540 mm
    • 0.25 in > 6.35
    • 6.35
      • H 533.65
      • V 953.65
  • reveal
    • Stock: 1050 x 700
    • Mine: 1920 x 1080

Printed page

  • Portrait:
    • Full page: 8.5 in x 11 in | 215.9 mm x 279.4 mm (0.7:1)
    • Standard publication boarder of 0.5 in: 7.5 in x 10 in | 177.8 mm x 254 mm
      • Full page guides at:
        • Horizontal: 0.5 in & 10.5 in | 12.7 mm & 266.7 mm
        • Vertical: 0.5 in & 8 in | 12.7 mm & 203.2 mm
    • Standard print boarder of 0.25 in: 8 in x 10.5 in | 203.2 mm x 266.7 mm
      • Full page guides at:
        • Horizontal: 0.25 in & 8.25 in | 6.35 mm & 209.55 mm
        • Vertical: 0.25 in & 10.75 in | 6.35 mm & 273.05 mm
  • Landscape:
    • Full page: 11 in x 8.5 in | 279.4 mm x 215.9 mm (1:0.7)
    • Standard publication boarder of 0.5 in: 10 in x 7.5 in | 254 mm x 177.8 mm
      • Full page guides at:
        • Horizontal: 0.5 in & 8 in | 12.7 mm & 196.85 mm
        • Vertical: 0.5 in & 10.5 in | 12.7 mm & 273.05 mm
    • Standard print boarder of 0.25 in: 10.5 in x 8 in | 266.7 mm x 203.2 mm
      • Full page guides at:
        • Horizontal: 0.25 in & 8.25 in | 6.35 mm & 209.55 mm
        • Vertical: 0.25 in & 10.75 in | 6.35 mm & 273.05 mm