Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Border Color of Border on Table- Kable

I am trying to create borders around specific columns in R. I am able to do this using the kableExtra package (shown below)

iris <- datasets::iris

iris2 <- do.call(data.frame, aggregate(. ~ Species, iris, function(x) c(mean = mean(x), sd = sd(x))))

res2 <- kable(iris2,"html", col.names =  c("Species", "Mean", "SD", "Mean", "SD", "Mean", "SD", "Mean", "SD"),   align = c("r","c","c","c","c","c","c","c","c")) %>%
  kable_styling(bootstrap_options = c("striped", "hover")) %>%
  add_header_above(c(" " = 1, "Sepal Length" = 2, "Sepal Width" = 2, "Petal Length" = 2, "Petal Width" = 2))

print(res2)

res3<- column_spec(res2, c(2,4,6,8), border_left = TRUE, border_right = FALSE)

column_spec(res3, c(3,5,7,9), border_left = FALSE, border_right = TRUE)

This creates the border I would like in the right positions, but I would like them to be gray and not black. I tried using the 'color=' from the column_spec function but it turns the whole column gray and not just the border.

res3<- column_spec(res2, c(2,4,6,8), border_left = TRUE, border_right = FALSE, color = "#D8D7D7")
column_spec(res3, c(3,5,7,9), border_left = FALSE, border_right = TRUE, color = "#D8D7D7")

Any suggestions on how to change the border color would be helpful! For now, I am using getAnywhere() to see if I can just change the function slightly.

like image 768
daszlosek Avatar asked Jan 30 '18 17:01

daszlosek


People also ask

How do you change the color of a table border?

Add or change a table border. Select the table cells that you want to add or change the table border for. Under Table Tools, on the Design tab, in the Draw Borders group, do one or more of the following: To change the color of the border, click the arrow next to Pen color, and then click the color that you want.

How do you change the border of a table cell?

Click the Table Design tab.) Click Border Styles and choose a border style. Click Borders and choose where you want to add the borders. Tip: To change or add borders for part of your table, check that Border Painter is selected and then, in the table, click each border that you want to change or add.


1 Answers

Use css into a border. This works

column_spec(res3, c(3,5,7,9), border_left = "2px solid gray",
            border_right = "2px solid gray")
like image 156
Winicius Sabino Avatar answered Sep 19 '22 13:09

Winicius Sabino