在`gt`嵌套表下面,如何更改文本颜色和大小

问题描述 投票:0回答:1

在下面

gt
嵌套表中,如何更改文本颜色和大小? 我在
color
中添加了
size
gt
,但不起作用。任何人都可以帮忙吗?谢谢!

library(gt)
library(tidyverse)

nested_data <- diamonds %>% head(10)%>% group_by(color) %>% 
  summarise(x=list(x),y=list(y))

nested_data %>% gt() # result as attached image

enter image description here

r gt
1个回答
0
投票

在下面的示例中,我按

x
创建了
y
color
的平均值表。然后,我将平均值大于
x
的所有
4.4
值设置为红色,将
x
y
的平均值设置为蓝色,其中
color == "J"
.

library(gt)
library(tidyverse)

diamonds %>% 
  head(100)%>% 
  group_by(color) %>% 
  summarise(x=mean(x),y=mean(y)) %>% 
  gt() %>%
  tab_style(
    style = list(
      cell_text(color = "red")
    ),
    locations = cells_body(
      columns = vars(x), 
      rows = x>4.4
    )) %>%
  tab_style(
    style = list(
      cell_text(color = "blue")
    ),
    locations = cells_body(
      columns = vars(x, y), 
      rows = color=="J"
    ))

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.