R語言如何創建任意大小的方格並在指定的方格內著色

21 views
Skip to first unread message

LJR

unread,
Apr 18, 2024, 8:54:07 PMApr 18
to R軟體使用者論壇
想請教R語言有指令可以創建任意大小的方格,並在指定的方格著色
例如:創建方格5×3,並指定方格第2列第3行、第1列第2要著上黃色
感謝回覆^^

WEPA ^_^

unread,
Apr 19, 2024, 11:56:13 AMApr 19
to R軟體使用者論壇
Hi friend,

參考以下使用 gt 套件,詳細參考 gt 套件線上說明。

# R程式碼:
library(dplyr)
library(gt)
df <- data.frame(matrix(1:15, ncol=3))
df %>%
  gt() %>%
  tab_options(column_labels.hidden = TRUE) %>%
  data_color(
    columns = c("X2"),
    rows = 1,
    palette = c("yellow")
  ) %>%
  data_color(
    columns = c("X3"),
    rows = 2,
    palette = c("yellow")
  )


# 執行結果:
gt_fill_color.png
#end
LJR 在 2024年4月19日 星期五上午8:54:07 [UTC+8] 的信中寫道:
Reply all
Reply to author
Forward
0 new messages