Description Usage Arguments Author(s) References Examples
Add a plot to a worksheet
1 2 | xlsx.addPlot(wb, sheet, plotFunction, startRow = NULL, startCol = 2,
width = 480, height = 480, ...)
|
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 |
Alboukadel Kassambara <alboukadel.kassambara@gmail.com>
http://www.sthda.com
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")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.