decide_plot_type | R Documentation |
This function determines the appropriate plot type based on the structure of the input data frame. Use only within 'plot_indicator()'
decide_plot_type(results_df)
results_df |
A data frame containing the results of the indicator. Needs to contain 'file', 'country', 'year' and 'value' columns. Use only within 'plot_indicator() |
The function determines the plot type based on the number of countries and years in the input data frame. If the data frame has multiple countries and multiple years, the plot type is a line plot with multiple lines. If the data frame has multiple years and only one country, the plot type is a line plot with one line. If the data frame has only one year and multiple countries, the plot type is a bar plot with multiple bars (sorted). If the data frame has only one year and only one country, the plot type is a bar plot with one bar.
A character string indicating the appropriate plot type. The possible values are:
"line": A line plot with one or multiple lines.
"bar": A bar plot with one or multiple bars.
# Create a test data frame
results_df <- data.frame(
file = c("us2010h", "us2011h", "ca2010h", "ca2011h"),
year = c(2010, 2011, 2010, 2011),
value = c(1, 2, 3, 4)
)
# Determine the appropriate plot type
decide_plot_type(results_df)
# Output: "line"
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.