Hi Woodward,
Thanks for the above code. However, it's for exporting a plotly chart to png.
I am using "officer" and "svg" packages for exporting charts to power-point. And, it works fine for ggplot2 charts but not for plotly charts.
Code:
count.data <- data.frame(
class = c("1st", "2nd", "3rd", "Crew"),
n = c(325, 285, 706, 885),
prop = c(14.8, 12.9, 32.1, 40.2)
)
count.data <- count.data %>%
arrange(desc(class)) %>%
mutate(lab.ypos = cumsum(prop) - 0.5*prop)
test_donut1 <- ggplot(count.data, aes(x = "", y = prop, fill = class)) +
geom_bar(width = 1, stat = "identity", color = "white") +
coord_polar("y", start = 0)+
geom_text(aes(y = lab.ypos, label = prop), color = "white")+
theme_void()
library("tidyverse")
library("officer")
library("rvg")
Create a new powerpoint document
doc <- read_pptx()
doc <- add_slide(doc, 'Title and Content', 'Office Theme')
Add the plot
doc <- ph_with_vg(doc, code = print(test_donut1), type = 'body')
print(doc, target = 'C:\plot7.pptx')