我必须在闪亮的应用程序中实现下载功能。这是一个示例代码:
library(rvg)
library(ggplot2)
library(officer)
library(highcharts)
library(jpeg)
library(ggplot2)
font.add.google("Open Sans", "myfont")
showtext.auto()
data(diamonds)
data <- subset(diamonds, color %in% c("E", "F", "G") & cut %in% c("Ideal", "Premium", "Good"))
data$indicator <- ifelse(data$color %in% c("G" ), 1, 0)
colors_hc <- c("#7CB5EC", "#313131", "#F7A35C",
"#90EE7E", "#7798BF", "#AAEEEE",
"#FF0066", "#EEAAEE", "#55BF3B",
"#DF5353", "#7798BF", "#AAEEEE")
theme_hc <- function(){
theme(
text = element_text(family = "myfont", size = 12),
title = element_text(hjust = 0),
axis.title.x = element_text(hjust = .5),
axis.title.y = element_text(hjust = .5),
panel.grid.major.y = element_line(color = 'gray', size = .3),
panel.grid.minor.y = element_blank(),
panel.grid.major.x = element_blank(),
panel.grid.minor.x = element_blank(),
panel.border = element_blank(),
panel.background = element_blank(),
legend.position = "bottom",
legend.title = element_blank()
)
}
plot1 <- ggplot(data) +
geom_bar(aes(color, fill = cut), position = "dodge", width = .4) +
ggtitle("Another interesting title") +
xlab("Cut") + ylab("Amount") +
scale_y_continuous(labels = scales::comma) +
scale_fill_manual(values = colors_hc) +
theme_hc()
plot2 <- ggplot(data) +
geom_bar(aes(color, fill = cut), position = "dodge", width = .4) +
ggtitle("Another interesting title") +
xlab("Cut") + ylab("Amount") +
scale_y_continuous(labels = scales::comma) +
scale_fill_manual(values = colors_hc) +
theme_hc()
plot3 <- ggplot(data) +
geom_bar(aes(color, fill = cut), position = "dodge", width = .4) +
ggtitle("Another interesting title") +
xlab("Cut") + ylab("Amount") +
scale_y_continuous(labels = scales::comma) +
scale_fill_manual(values = colors_hc) +
theme_hc()
doc <- read_pptx()
doc <- add_slide(doc, layout = "Title and Content", master = "Office Theme")
doc <- doc %>%
ph_with_text(type = "title", str = "Marktanteil bei x am Besten in Y") %>%
ph_with_text(type = "ftr", str = "MP Dashboard Report") %>%
ph_with_text(type = "dt", str = format(Sys.Date())) %>%
ph_with_text(type = "sldNum", str = "Folie1")
doc <- ph_with_vg(doc, ggobj = plot1, type = "body")
doc <- add_slide(doc, layout = "Title and Content", master = "Office Theme")
doc <- doc %>%
ph_with_text(type = "title", str = "Marktanteil bei x am Besten in Y") %>%
ph_with_text(type = "ftr", str = "MP Dashboard Report") %>%
ph_with_text(type = "dt", str = format(Sys.Date())) %>%
ph_with_text(type = "sldNum", str = "Folie2")
doc <- ph_with_vg(doc, ggobj = plot2, type = "body")
doc <- add_slide(doc, layout = "Title and Content", master = "Office Theme")
doc <- doc %>%
ph_with_text(type = "title", str = "TV in Deutschland um 10% weniger wichtig als in D") %>%
ph_with_text(type = "ftr", str = "MP Dashboard Report") %>%
ph_with_text(type = "dt", str = format(Sys.Date())) %>%
ph_with_text(type = "sldNum", str = "Folie2")
doc <- ph_with_vg(doc, ggobj = plot3, type = "body")
print(doc, target = "C:/user/my_plot.pptx")
###
对于高级图表,使用如下所示的内容也不起作用:
png("sample.png", 490, 350)
plot(x, y, pch=19, col=rgb(0.5, 0.5, 0.5, 0.5), cex=1.5)
abline(lm(y ~ x))
dev.off()
似乎Highcharts使用一种特殊的对象,该对象不能在R本身内转换为R。否则可以通过R-Studio中的按钮下载图表。
我的应用程序使用高位图,但将每个图表重写为ggplot2代码实际上没有任何意义。有人对此有经验吗?