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:
These magic strings roughly align with the plotting function brew templates in
./inst/site_template/plotting_functions/
.
csv_url
column in place of URL to a csv file.csv_url
column in place of the URL to csv file.plotting_function_call
is empty or NA
.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')"
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:
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.