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
)

Arguments

filename

filename of the Excel workbook you wish to create. Can be a file path, but the directory must already exist.

object

ggplot2 chart to create chart data from. If left blank, ggplot2::last_plot() is used to get the last plot displayed.

type

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.

height

Numeric, optional. Use this to override the default height for plots of your chosen `type`; see ?grattan_save for more details.

Examples


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)