Es gibt Pakete, die dies tun. Das Paket, das momentan die direkteste Schnittstelle hat, ist wahrscheinlich condformat
mit der condformat::rule_file_discrete
Funktion. Ich habe leider kein funktionierendes Beispiel, da ich condformat
rJava
benötige, was mit meinem System nicht gut auskommt.
Das pixiedust
Paket (vollständige Offenlegung, ich bin der Autor) kann dies erreichen, aber es ist nicht sehr direkt im Moment.
library(pixiedust)
library(scales)
library(magrittr)
# Make the table (as a matrix, but a data frame would work as well)
set.seed(pi)
X <- matrix(sample(1:10,
size = 100,
replace = TRUE),
nrow = 10)
# Define 10 colors
background <- hue_pal()(10) %>%
setNames(1:10)
show_col(background)
# Convert X to a dust object
X_dust <- dust(X)
# Apply the background colors
for (i in sort(unique(as.vector(X)))){
X_dust <-
sprinkle(X_dust,
rows = X_dust$body$row[X_dust$body$value == i],
cols = X_dust$body$col[X_dust$body$value == i],
bg = background[i],
fixed = TRUE)
}
# Print the HTML code
X_dust %>%
sprinkle_print_method("html")
Ich bin derzeit Code zu entwickeln, dies zu tun mit nur wenigen Zeilen Code, aber das Feature ist noch nicht ganz bereit für die Freigabe.
ist es unklar, was Sie suchen. Sie können in Tabellen in R nicht "einfärben". Möchten Sie dies in einer HTML-Tabelle, einer Excel-Tabelle oder einem anderen Tabellenformat machen? –
also gibt es kein Paket, um eine Tabelle so zu planen, wie ich will? –
Bitte erläutern Sie, in welchem Format die Tabelle gedruckt werden soll. Hier sind ein paar Tipps, wie man ein [reproduzierbares Beispiel] (http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) seinen Namen verdient. –