表焦点 - 根据多个列的价值更改文本颜色
我想复制下表,在Tableau中称为 spotlighting
在我的情况下,我想用以下基础复制它,使我对每行的最大值,这是我有一个想法的问题使用cell_spec()
从kableExtra
package
library(knitr)
library(kableExtra)
Name<-c("question1", "question", "question3", "question4",
"question5", "question6", "question7", "question8",
"question9", "question10")
A<-c(0, 3 ,0 ,1, 0, 0, 0, 0, 2, 0)
B<-c(5, 0, 1, 0, 3, 0, 3, 1, 0, 1)
C<-c(3, 0, 2 ,2 ,0 ,1, 0 ,1 ,0 ,2)
D<-c(4, 1, 3 ,2 ,0 ,5, 0 ,1 ,3 ,2)
tab<-data.frame("Name"=Name,"A"=A,"B"=B,"C"=C,"D"=D)
tab%>%
kbl() %>%
kable_paper("striped",full_width = F)
请记住,我想获得具有类似格式的表仅显示表中最多的数字
I would like to replicate the following table that in tableau is called Spotlighting
In my case I would like to replicate it with the following base that gives me color to the maximum value per row that are the questions I have an idea to do it with cell_spec()
from the kableExtra
package
library(knitr)
library(kableExtra)
Name<-c("question1", "question", "question3", "question4",
"question5", "question6", "question7", "question8",
"question9", "question10")
A<-c(0, 3 ,0 ,1, 0, 0, 0, 0, 2, 0)
B<-c(5, 0, 1, 0, 3, 0, 3, 1, 0, 1)
C<-c(3, 0, 2 ,2 ,0 ,1, 0 ,1 ,0 ,2)
D<-c(4, 1, 3 ,2 ,0 ,5, 0 ,1 ,3 ,2)
tab<-data.frame("Name"=Name,"A"=A,"B"=B,"C"=C,"D"=D)
tab%>%
kbl() %>%
kable_paper("striped",full_width = F)
Remember that I want to get a table with a similar format only that now I will only show the largest number in the table
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过数字列循环并根据值添加颜色(根据需要更改 ifelse 语句):
“ nofollow noreferrer”>
Loop through the numeric columns and add a colour based on the value (change the ifelse statement as needed):
Edit:
To do the same per row, we can transpose, then as above loop through columns and change the colour based on value, then transpose it back again: