Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dml() interacting with ggtext() elements #57

Open
nickjparkinson opened this issue Oct 29, 2024 · 0 comments
Open

dml() interacting with ggtext() elements #57

nickjparkinson opened this issue Oct 29, 2024 · 0 comments

Comments

@nickjparkinson
Copy link

nickjparkinson commented Oct 29, 2024

Having trouble getting the rvg package to work with html and markdown formatting options in ggtext (for example, using theme(element.subtitle = geom_richtext() or using geom_richtext()).

geom_richtext() produces misaligned boxes in the vector (see image), and when added to a PPT content placeholder, the subtitle just renders the raw html or markdown.

Min reprex below.

ibrary(tidyverse)
library(officer)
library(rvg)
library(ggtext)

plot <- 
  ggplot(mtcars, aes(x = wt, y = mpg, col = factor(am))) +
  geom_point() +
  # Add richtext legend
  geom_richtext(data = ~last(.), 
                aes(x = 4, 
                    y = 30, 
                    label = "<span style = 'color:#00BFC4;'>Automatic</span>
         <br><span style = 'color:#F8766D;'> Manual</span>"),
                fill = NA, label.color = NA) +
  # Add markdown subtitle
  labs(title = "Heavier cars use more gallons per mile", 
       subtitle = "Fuel efficiency in miles per gallon for <span style = 'color:#00BFC4;'>automatic</span>
         and<span style = 'color:#F8766D;'> manual</span> cars", 
         x = "Weight") +
  theme_minimal() +
  theme(plot.subtitle = element_markdown(size = 11, lineheight = 1.2),
        legend.position = 'none')

editable_graph <- dml(ggobj = plot)
doc <- read_pptx()
doc <- add_slide(doc)
doc <- ph_with(x = doc, editable_graph,
               location = ph_location_type(type = "body") )

print(doc, target = "example.pptx")

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant