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/.

  • “plot_none” : Create no plot for this indicator. Useful if you just want captions.
  • “embed_html” : use a pre-made, externally-hosted html plot. URL to the html file is passed in the csv_url column in place of URL to a csv file.
  • “include_graphic” : use a pre-made jpg, png, or other image. URL to the image is passed in the csv_url column in place of the URL to csv file.
  • “plot_dygraph_timeseries” : Creates an interactive timeseries plot using dygraph. This is the current default behavior if plotting_function_call is empty or NA.

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 :

  • "print(""This is my custom plotter code all shoved into a single column directly in the csv file AND a bunch of commas: ,,,,,a,b,c,123,,,!"")"
  • "plot_dygraph_timeseries(csv_tv='https://raw.githubusercontent.com/marinebon/info-fk/master/prep/data/rvc_trophic_groups/lionfish_bio.csv', title='Lionfish Biomass', y_label='Mean Biomass (g/40Mm^2)', col_t='YEAR', col_y='biomass_mean', std_err='biomass_se')"

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%> ...")
    #> [1] "loading data from <%=csv_url%> ..."
    print("...just kidding, let's use fake data to keep this simple.")
    #> [1] "...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)
    ```
    
    <img src="/private/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/Rtmplg6KUw/file9573c1d0d46/articles/plotting_function_call_files/figure-html/unnamed-chunk-1-1.png" width="700" />
    
    ```r
    print ("<%=plot_caption%>")
    #> [1] "<%=plot_caption%>"
    
    print("I can use the columns from plot_indicators using brew template formatting.")
    #> [1] "I can use the columns from plot_indicators using brew template formatting."
    print("svg id is <%=svg_id%>")
    #> [1] "svg id is <%=svg_id%>"
    print("<%=col_t%> vs <%=col_y%>")
    #> [1] "<%=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:

  • csv_url
  • svg_id
  • col_t
  • col_y