I have a table that I made with the kableExtra
package in R, using kbl()
. Each row has a state abbreviation, like 'NJ', 'ME', etc, and the columns have info about each state.
Is there an easy way to add a column that just has the shape pictures of the states? This would make it easy to quickly identify states. like the row with NJ would have the shape of NJ next to it.
Edit: I know how to add an image to the table, as discussed here: Add an image to a table-like output in R, but I'm specifically looking for a way to get the US state shapes.
This is the new edit following this answer. You could use this example to put shapes next to the state abbreviation:
Html ouput
---
title: "Shapes"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
library(tidyverse)
library(kableExtra)
```
```{r, echo=FALSE}
tbl_img <-data.frame(
name = c("alabama", "alaska"),
abbr = c("AL", "AK"))
tbl_img$shape <- sprintf('{width=25px}', tbl_img$name)
tbl_img %>%
select(-name) %>%
kbl(booktabs = T) %>%
kable_paper(full_width = F)
```
-output