Reputation: 77
I'm looking for ways to plot the tables with cells filled by colors in R environment. Dose somebody know how to make the this kind of plot in R, as shown below.
I can get the similar plot using ggplot2 package, but I'm unable to extend the lines of rows and colums.
Any help for this question will be greatly appreciated.
Upvotes: 1
Views: 1567
Reputation: 2864
I would stick with the knitr::kable
& kableExtra
combination when it comes to HTML tables in R. You can refer to this online documentation and take a look at the example below, which is taken from the documentation.
library(kableExtra)
library(formattable)
mtcars[1:5, 1:4] %>%
mutate(
car = row.names(.),
mpg = color_tile("white", "orange")(mpg),
cyl = cell_spec(cyl, angle = (1:5)*60,
background = "red", color = "white", align = "center"),
disp = ifelse(disp > 200,
cell_spec(disp, color = "red", bold = T),
cell_spec(disp, color = "green", italic = T)),
hp = color_bar("lightgreen")(hp)
) %>%
select(car, everything()) %>%
kable(escape = F) %>%
kable_styling("hover", full_width = F) %>%
column_spec(5, width = "3cm") %>%
add_header_above(c(" ", "Hello" = 2, "World" = 2))
Upvotes: 3