在我的上一篇文章中,没有足够的信息。所以我用更多的信息重新发布它... 我想以excel横向格式导出r闪亮的表格和图表。
我怎么能这样做?
谢谢
我试过了:
wb <- createWorkbook(type="xlsx")
sheet <- xlsx::createSheet(wb, sheetName = "Sheet1")
xlsx.addTable(wb, sheet, tabA, startCol=2)
xlsx.addTable(wb, sheet, tabB, startCol=8)
xlsx.addTable(wb, sheet, tabG, startCol=1)
xlsx.addTable(wb, sheet, tabE, startCol=12)
plotFunction<-function(){
library(ggplot2)
p1 <- ggplot(data = tt_total, aes(x = VAR1, y = VAR2))+geom_bar(stat = "identity",aes(fill = VAR2))+scale_fill_gradient(low="#56B4E9", high="blue") + labs(y = "XXX", x = NULL)+ggtitle("XXX")
p2 <- ggplot(tt_total, aes(x=VAR1, y=VAR2, group=a, colour=VAR3))+xlab("Time")+ylab("PET")+geom_point(colour = "orange")+ geom_line(colour = "orange",size=1.5)+ labs(y = "XXX", x = NULL)+theme_bw() %+replace% theme(panel.background = element_rect(fill = NA))
g1 <- ggplot_gtable(ggplot_build(p1))
g2 <- ggplot_gtable(ggplot_build(p2))
pp <- c(subset(g1$layout, name == "panel", se = t:r))
g <- gtable_add_grob(g1,
g2$grobs[[which(g2$layout$name == "panel")]],
pp$t, pp$l, pp$b, pp$l)
alab <- g2$grobs[[which(g2$layout$name=="ylab")]]
ia <- which(g2$layout$name == "axis-l")
ga <- g2$grobs[[ia]]
ax <- ga$children[[2]]
ax$widths <- rev(ax$widths)
ax$grobs <- rev(ax$grobs)
ax$grobs[[1]]$x <- ax$grobs[[1]]$x - unit(1, "npc")+unit(0.15, "cm")
g <- gtable_add_cols(g, g2$widths[g2$layout[ia, ]$l],
length(g$widths) - 1 )
g <- gtable_add_cols(g, g2$widths[g2$layout[ia, ]$l],
length(g$widths) - 1 )
g <- gtable_add_grob(g, ax, pp$t, length(g$widths) - 2, pp$b)
g <- gtable_add_grob(g, alab, pp$t, length(g$widths) - 1, pp$b)
grid.draw(g))}
xlsx.addPlot(wb, sheet, plotFunction())
xlsx::saveWorkbook(wb, Path/examples_add_header.xlsx")