1

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

ryut
  • 13
  • 3

1 Answers1

1

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

Kat
  • 15,669
  • 3
  • 18
  • 51
  • Thank you so much for your response. Yes, I was able to achieve the shading.color prior but I'm referencing the padding color around the text (as in linked png - orange color). It seems as if there's still color remaining unfilled when you select the data label. I can set the shading.color to be "#767171" for the text but once its opened in PowerPoint and you select the label, there still remains a white color around the text. – ryut May 27 '22 at 13:12
  • I'm sorry. I'm not following. I added a background color to the slide and still wasn't able to find another layer of color. If I selected the label it looked like there was more color, but it was just the 'active' box. Can you elaborate a bit further? Perhaps the difference is because I use MS Office for Mac 2021? – Kat May 27 '22 at 17:15
  • Possibly. For example, when I'm in PowerPoint and then select the data series, I would then select "Shape Fill" under Format to access the fill color I'm interested in achieving. The Shape Fill color fills the whole data label color. With the current shading.color option in mschart, the text gets filled with a shading color but it leaves a white color of padding outside the shading.color. As if it would require me to go into the Powerpoint as a secondary step and match the Shape Fill color to the shading.color so the whole data label is one color. – ryut May 27 '22 at 17:36