save_chartdata.Rd
Grattan reports are accompanied by Excel workbooks containing the data used to produce the chart ("chart data") and the chart itself. This function takes a ggplot2 object and creates a single-sheet Excel workbook with the chart data and chart. If your ggplot2 object has a subtitle and caption, those will be properly displayed in the spreadsheet.
save_chartdata(
filename,
object = ggplot2::last_plot(),
type = "normal",
height = NULL,
select_data = TRUE,
round = NULL
)
filename of the Excel workbook you wish to create. Can be a file path, but the directory must already exist.
ggplot2 chart to create chart data from. If left blank,
ggplot2::last_plot()
is used to get the last plot displayed.
type of plot. Default is "normal". See ?grattan_save
for
full list of types. Note that if labels (title,
subtitle, caption) are included in your chart and height is not manually
specified with the `height` argument, the plot height will be expanded a
little to accommodate the labels.
Numeric, optional. Use this to override the default height
for plots of your chosen `type`; see ?grattan_save
for more details.
Logical, default is TRUE. Removes any columns that are not used in ggplot mappings and facets from the exported chart data.
Numeric, optional. Round numbers in the chart data to this number of decimal places. Default is NULL, which does not round numbers.
library(ggplot2)
p <- ggplot(mtcars, aes(x = wt, y = mpg)) +
geom_point() +
theme_grattan() +
labs(title = "Title",
subtitle = "Subtitle",
caption = "Caption")
if (FALSE) save_chartdata("my_chartdata.xlsx", p) # \dontrun{}