I have a table containing the presence (+) of species (lines) according to years (columns).
The idea is to italicize the Latin name of each species and to color the lines according to a certain characteristic of the species. Unfortunately, I can't do both at the same time.
The first thing I managed to get is the right color for each line:
library(dplyr)
library(flextable)
mydata <- data.frame(Espèce = c("Acipenser Sturio (L. 1758) Esturgeon européen",
"Alosa alosa (L.1758) Alose vraie", "Alosa fallax (Lac. 1803) Alose feinte",
"Anguilla anguilla (L. 1758) Anguille", "Lampetra fluviatilis (L. 1758) Lamproie de rivière",
"Liza ramada (Risso 1826) Mulet porc") ,
`00` = c("", "+", "+", "+", "", "+"),
`01` = c("", "+", "+", "+", "+", "+"))
flextable(mydata) %>%
color(color = c(rep("firebrick2",2),rep("black",3),rep("dodgerblue3",1)))
And when I try to add the italic font (the text before the open bracket), words in italic lose the color previously defined:
mydata %>%
flextable(col_key=c("dummy_col",names(mydata)[-1])) %>%
color(color=c(rep("firebrick2",2),rep("black",3),rep("dodgerblue3",1)), part="body")%>%
display(col_key = "dummy_col", pattern = "{{id_}} ({{sciname_}}",
formatters = list(id_ ~ unlist(strsplit(paste(mydata$Espèce[1:(length(mydata$Espèce))]), split="\\("))[seq(1,length(unlist(strsplit(paste(mydata$Espèce[1:(length(mydata$Espèce))]), split="\\("))),2)],
sciname_ ~ unlist(strsplit(paste(mydata$Espèce[1:(length(mydata$Espèce))]), split="\\("))[seq(2,length(unlist(strsplit(paste(mydata$Espèce[1:(length(mydata$Espèce))]), split="\\("))),2)]),
fprops = list(id_ =fp_text(italic = TRUE))) %>%
color(j="dummy_col", color=c(rep("firebrick2",2),rep("black",3),rep("dodgerblue3",1)))
Would you have any suggestion to get both at the same time, namely the italicized text in the right color?