I am wonder if its possible reverse the size of the color_bar
command in formattable
, example:
library(formattable)
df = data.frame(Ranking = c(1, 2, 3, 4, 5, 8, 10))
formattable(df, list(Ranking = color_bar("red")))
My table result is:
Is it possible get the largest bar in number 1
and the shortest bar in number 10
? I have a Ranking
column where the 1
number is the best ranking.
EDIT1
Other solution that work for me is omit or remove the number in the color_bar
.
EDIT2:
Other question : How I could center the header?
My code:
formattable(df, align =c("c"), list(Ranking= color_bar("red")))
CodePudding user response:
Try this solution:
```{r, include=FALSE, warning=FALSE}
library(formattable)
InvProp = function(x) (1.05 - ((x) / (max(x)))) #inverse proportion
#make our formattable
df = data.frame(" " = c(1, 2, 3, 4, 5, 8, 10, 15), check.names=FALSE)
table2 <- formattable(df, list(" " = color_bar("red", InvProp)))
```
#you can modify title style with html and css, as you wish
<center>
<caption>My formattable</caption>
</center>
`r table2`