I have an euler plot created with eulerr
package.
Sample data:
fit <- euler(c(
"A" = 10000,
"B" = 7000,
"A&B" = 600))
plot(fit,
quantities = list(fontsize = 9),
fills = c("#8ABDAF", "#DC8E8D"),
fontsize = 9,
main = list(label = "Title"),
labels = NULL,
legend = list(labels = c("A", "B"))
)
I want to export this base R plot to powerpoint not as an image but in a way where I can modify each element.
As it's not a ggplot, I can't export using export
package. But it does seem like there is a possibility with a combination of the officer
and rvg
packages.
I've seen another thread using the function ph_with_vg
from the rvg
package, but after installing rvg that function is not existing.
I tried the following:
read_pptx() %>%
add_slide(layout = "Title and Content", master = "Office Theme") %>%
ph_with(dml(code = {
plot(fit)
}),
location = ph_location_type(type = "body")) %>%
print(target = "Euler_fit.pptx")
But I get the error:
Error in read_xml.raw(charToRaw(enc2utf8(x)), "UTF-8", ..., as_html = as_html, :
StartTag: invalid element name [68]
I have no idea what that means.
Does anybody know how to do this?
Thanks.
Note that this is a grid plot and not a base plot.
You are just missing a plot
statement:
library(eulerr)
library(rvg)
library(officer)
fit <- euler(c(
"A" = 10000,
"B" = 7000,
"A&B" = 600))
p <- plot(fit,
quantities = list(fontsize = 9),
fills = c("#8ABDAF", "#DC8E8D"),
fontsize = 9,
main = list(label = "Title"),
labels = NULL,
legend = list(labels = c("A", "B"))
)
read_pptx() |>
add_slide(layout = "Title and Content", master = "Office Theme") |>
ph_with(dml(code = {
plot(p)
}),
location = ph_location_type(type = "body")) |>
print(target = "Euler_fit.pptx")