如何在 R markdown 中突出显示数据框中的特定单元格 HTML

How to highlight specific cells in a dataframe in R markdown HTML

我有一个如下所示的数据框(数据列在问题的末尾):

如您所见,我想在演示文稿的最终 R-Markdown 报告中突出显示几个单元格。我当前的代码只能显示 table:

cluster_summary%>% kbl(caption = '<b>Clustering results</b>') %>%
  kable_classic(full_width = F, html_font = "Cambria")

如何突出显示这些单元格?

数据

structure(list(cluster = structure(1:7, .Label = c("1", "2", 
"3", "4", "5", "6", "7"), class = "factor"), n = c(512L, 1048L, 
662L, 1968L, 576L, 1738L, 1188L), ave_price_per_sqft_adjusted = c(5.16299733157459, 
3.32371811588978, 3.96858531607868, 3.32922072520205, 3.42896017156734, 
4.16418851265888, 4.08627345683475), ave_age = c(12.0393129995492, 
12.6062546474121, 9.32033699503113, 25.5092197801581, 19.1151284494788, 
12.2180810585854, 12.0248580167839), ave_DOM = c(47.706537201211, 
42.0442099665614, 49.9960193152193, 34.2190863941281, 44.5416652882415, 
37.1891219996921, 33.3872422432855), ave_activity_rate = c(1.20118970114087, 
1.14598100690658, 1.47458159497434, 1.58286371628597, 1.31320615630511, 
1.32586511589676, 2.90376115653893), topic_1 = c(0.0873152283441761, 
0.0402887288191615, 0.0671677410154403, 0.0658325530416239, 0.0486383977595131, 
0.678477957074527, 0.124182893709105), topic_2 = c(0.0432613598954236, 
0.0696506982126008, 0.0443719103703934, 0.714018587278257, 0.106997881943579, 
0.0858546713546651, 0.123859196751554), topic_3 = c(0.734165987470995, 
0.0151590853651532, 0.0274370600921245, 0.0267196491438714, 0.0186524676995082, 
0.0422361263557554, 0.0476136227502999), topic_4 = c(0.0268470362758521, 
0.0222984614059603, 0.035088529448869, 0.0682401425738628, 0.733361959255753, 
0.0345517467883103, 0.0701685629335576), topic_5 = c(0.0236832387869678, 
0.0195300786802868, 0.681931511958987, 0.01084326403663, 0.00780696913319592, 
0.0271831270677069, 0.0256968988305932), topic_6 = c(0.00241582961309524, 
0.00512777524684262, 0.043572436212494, 0.00284832693741011, 
0.00466231684981685, 0.00447461706422522, 0.00578628373290925
), topic_7 = c(0.0293156710834479, 0.0165055511133993, 0.0243384949312766, 
0.0479052429538088, 0.0240980295134035, 0.035084908174513, 0.531063470492252
), topic_8 = c(0.0519347465414063, 0.808840100571256, 0.0730651082702796, 
0.0592810817199474, 0.0538401481417729, 0.0805723035106479, 0.0664648058614109
)), class = "data.frame", row.names = c(NA, -7L))

您可以使用 formattable,参见 these examples
color_tile 格式化程序结合 area 选项允许更改特定行和列的颜色。

library(formattable)

highlight <- color_tile("yellow","yellow")

formattable(data, list(
  area(col = 3, row = 1 ) ~ highlight,
  area(col = 4, row = 4 ) ~ highlight
  ))