rcolorsfooterflextable

Changing colors within my footer in flextable


I have certain words in my flextable footer lines that I would like to be a different color. Here is an example using the example iris data.

library(flextable)

ft_1 <- flextable(head(iris))
ft_1 <- add_footer_lines(ft_1,
                     values = c("This is red", "This is yellow"))

I would like just the word "red" and "yellow" to be their respective colors. I'm not sure how to accomplish this within this package.


Solution

  • library(flextable)
    
    ft_1 <- flextable(head(iris))
    ft_1 <- add_footer_lines(ft_1, 
                             value = as_paragraph(
                               "This is ", as_chunk("red", 
                                    props = fp_text_default(color = "red"))))
    ft_1 <- add_footer_lines(ft_1, 
                             value = as_paragraph(
                               "This is ", as_chunk("yellow", 
                                    props = fp_text_default(color = "gold"))))
    ft_1
    

    Created on 2024-07-11 with reprex v2.0.2