0

I have obtained the below table using the formattable function in R.

the table I got

I want to color the header row and the very last row (Total row) in color blue. I want to bold the text on the header and the word "Total" on the last row. Also, I want to add upper and lower boarders to the mentioned rows.

How can I do it using the "formattable" function in R? What changes should be done to my R code to get the exact output I need?

Please help!

Here is my R code:

formattable(Merged_Data, align =c("l","c","c","c"), 
            list(`Indicator Name` = formatter("span", style = ~ style(color = "black",font.weight = "bold")),
              `Male`= formatter("span", style = ~ style(color = ifelse(`Male` > "80%", "green", ifelse(`Male`>="75%", "black" ,"red"))),
                                   ~ icontext(ifelse(`Male` > "80%","glyphicon glyphicon-triangle-top", ifelse(`Male`>="75%","star" ,"glyphicon glyphicon-triangle-bottom")), `Male`)),
                 `Female`= formatter("span", style = ~ style(color = ifelse(`Female` > "80%", "green", ifelse(`Female`>="75%", "black" ,"red"))),
                                     ~ icontext(ifelse(`Female` > "80%","glyphicon glyphicon-triangle-top", ifelse(`Female`>="75%","star" ,"glyphicon glyphicon-triangle-bottom")), `Female`)),
                 `Children`= formatter("span", style = ~ style(color = ifelse(`Children` > "80%", "green", ifelse(`Children`>="75%", "black" ,"red"))),
                                       ~ icontext(ifelse(`Children` > "80%","glyphicon glyphicon-triangle-top", ifelse(`Children`>="75%","star" ,"glyphicon glyphicon-triangle-bottom")), `Children`)) 
            ))
Darsh
  • 21
  • 1
  • It would be easier to help you if you provide [a minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) including a snippet of your data or some fake data. – stefan Jul 13 '23 at 22:43
  • Hi, the data are exactly what was given in the table. It has four columns City, Male, Female and Children. City is the only categorical variable while others are percentages. – Darsh Jul 13 '23 at 22:48
  • Unfortunately data from images isn't that useful as we can't run your code based on an image. See https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-errors-when-asking-a-question/285557#285557 – stefan Jul 13 '23 at 22:53

0 Answers0