knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

Infographiq attempts to choose default plotting functions automatically, but there are times when you want to plot in a specific way. The (optional) plotting_function_call column in plot_indicators can be used to tell infographiq how to plot the data for each indicator.

plotting_function_call can be set to:

  1. nothing, allowing infographiq to use defaults.
  2. a "magic string" that infographiq can recognize and know what to do.
  3. an R function call.
  4. a filepath to a brew template

Using "magic strings"

These magic strings roughly align with the plotting function brew templates in ./inst/site_template/plotting_functions/.

Using R Function Calls

R code can be put directly into the plotting_function_call column. Code should be wrapped in quotes and quotes within the code must be doubled (""). Any arbitrary R code can be executed in this way and the output will be put in the modal. Examples :

Using brew templates

Cramming code into csv columns is ugly, so you can put R code into a brew template file and the pass the filepath in the plotting_function_call to create a custom plot at site-build-time.

As an example, consider we have the following brew template file in "/home/me/my_custom_plotting_function.rmd.brew":

    My Custom Plot : <%=plot_title%>
    -----------------------------
    I can put [markdown](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet) formatting here.

    Also I can execute R code and see the result in the modal.

    ```r
    # in this file we use a custom plotting method to plot data from the
    # csv_url. These comments within the R block won't show up in the output.

    print("loading data from <%=csv_url%> ...")
    print("...just kidding, let's use fake data to keep this simple.")

    # Define the vector with 5 values
    my_data <- c(1, 3, 6, 4, 9)

    # output my custom graph
    barplot(my_data)
    print ("<%=plot_caption%>")

    print("I can use the columns from plot_indicators using brew template formatting.")
    print("svg id is <%=svg_id%>")
    print("<%=col_t%> vs <%=col_y%>")
    ```

We can put /home/me/my_custom_plotting_function.rmd.brew in the plotting_function_call column and the output will be rendered into the modal. Note the variables available in the rendering context of the brew template:



marinebon/infographiqR documentation built on Dec. 21, 2021, 2:44 p.m.