xlsx.addPlot: Add a plot to a worksheet

Description Usage Arguments Author(s) References Examples

View source: R/r2excel.r

Description

Add a plot to a worksheet

Usage

1
2
xlsx.addPlot(wb, sheet, plotFunction, startRow = NULL, startCol = 2, 
            width = 480, height = 480, ...)

Arguments

wb

workbook object

sheet

sheet object

plotFunction

a plotting function

startRow

a numeric value specifying the starting row

startCol

a numeric value specifying the starting column

width

width of the plot

height

height of the plot

...

others arguments to png() function

Author(s)

Alboukadel Kassambara <alboukadel.kassambara@gmail.com>

References

http://www.sthda.com

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# create an Excel workbook. Both .xls and .xlsx file formats can be used.
wb <- createWorkbook(type="xlsx")
# Create a sheet in that workbook
sheet <- createSheet(wb, sheetName = "example1")
 
# basic box plot
data(ToothGrowth)
xlsx.addHeader(wb, sheet, "Basic box plot")
xlsx.addLineBreak(sheet, 1)
plotFunction<-function(){boxplot(len ~ dose, data = ToothGrowth, col = 1:3)}
xlsx.addPlot(wb, sheet, plotFunction())

# ggplot2
library("ggplot2")
xlsx.addHeader(wb, sheet, "ggplot2")
xlsx.addLineBreak(sheet, 1)
plotFunction<-function(){
  p<-qplot(mpg, wt, data=mtcars)
  print(p)
  }
xlsx.addPlot(wb, sheet, plotFunction())


# saving a workbook to an Excel file and write the file to the disk.
saveWorkbook(wb, "examples_add_plot.xlsx")

kassambara/r2excel documentation built on May 20, 2019, 7:40 a.m.