Mschart R to display chart data label fill color

272 views Asked by At

I would like to be able to add the orange color around the text. In PowerPoint, I can achieve this by formatting the data label fill color. Below is the code in R I'm using to set the shading color around the text but I don't know where I can set the color in the chart_data_labels function in the mschart R package. Thank you in advance.

fp_text_settings <- list(`C` = fp_text(color = "white",shading.color = "#767171",font.size = 10, font.family = "Century Gothic")

enter image description here

1

There are 1 answers

3
Kat On

You would set this in the chart theme, not in chart_data_labels. The manner in which you document these for mschart is extremely similar to how it comes together for ggplot2.

For example, I could identify the styles in the theme as I did in this example.

library(officer)
library(mschart)

# define special theme requirements
mytheme <- mschart_theme(axis_title = fp_text(color = "white", 
                                              shading.color = "#767171",
                                              font.size = 24, 
                                              bold = TRUE))
# create bar chart
bc <- ms_barchart(data = mtcars %>% 
                    mutate(cyl = as.factor(cyl)),
                  x = "cyl", y = "mpg")
# apply the theme
bc <- set_theme(bc, mytheme)

# update the labels
bc <- chart_labels(bc, title = "Cars", 
                   xlab = "Engine Cylinders",
                   ylab = "Miles per Gallon")

# create the pptx
mp <- read_pptx()

# create the slide
mp <- add_slide(mp, layout = "Title and Content", master = "Office Theme")

# add content to the slide
mp <- ph_with(mp, bc, location = ph_location_fullsize())

# create temp file and save pptx to temp file
fo <- tempfile(fileext = ".pptx")
print(mp, target = fo)

enter image description here