Add count labels to statebin map: how?

How can we add labels with the counts to each bin in the above statebin heatmap?

library(statebins)

dat = data.frame(state = state.abb, val = rep(0:24, 2))
dat$lab = paste(dat$state, dat$val, sep = "\n")
head(dat)
#   state val   lab
# 1    AL   0 AL\n0
# 2    AK   1 AK\n1
# 3    AZ   2 AZ\n2
# 4    AR   3 AR\n3
# 5    CA   4 CA\n4
# 6    CO   5 CO\n5

sb = statebins(dat, state_col = "state", value_col = "val") +
  geom_statebins_label(aes(label = lab)) +
  theme_statebins()
sb

enter image description here

How can we add labels with the counts to each bin in a statebin heatmap?

library(statebins)

dat = data.frame(state = state.abb, val = rep(0:24, 2))
dat$lab = paste(dat$state, dat$val, sep = "\n")

sb = statebins(dat, state_col = "state", value_col = "val") +
  geom_statebins_label(aes(label = lab)) +
  theme_statebins()
sb

enter image description here

How can we add labels with the counts to each bin of a statebin heatmap?

library(statebins)

dat = data.frame(state = state.abb, val = rep(0:24, 2))
dat$lab = paste(dat$state, dat$val, sep = "\n")

sb = statebins(dat, state_col = "state", value_col = "val") +
  geom_statebins_label(aes(label = lab)) +
  theme_statebins()
sb

enter image description here

How can we add labels with the counts to each bin of a statebin heatmap?

library(statebins)

dat = data.frame(state = state.abb, val = rep(0:24, 2))
dat$lab = paste(dat$state, dat$val, sep = "\n")

sb = statebins(dat, state_col = "state", value_col = "val") +
  geom_statebins_label(aes(label = lab)) +
  theme_statebins()

How can we add labels displaying the counts to each bin of a statebin heatmap?

library(statebins)

dat = data.frame(state = state.abb, val = rep(0:24, 2))
dat$lab = paste(dat$state, dat$val, sep = "\n")

sb = statebins(dat, state_col = "state", value_col = "val") +
  geom_statebins_label(aes(label = lab)) +
  theme_statebins()

How can we add labels showing the counts to each bin of a statebin heatmap?

To add labels with the counts to each bin in a statebin heatmap, you can use the geom_statebins_label() function from the statebins package. Here is the code to achieve this:

library(statebins)

dat = data.frame(state = state.abb, val = rep(0:24, 2))
dat$lab = paste(dat$state, dat$val, sep = "\n")

sb = statebins(dat, state_col = "state", value_col = "val") +
  geom_statebins_label(aes(label = lab)) +
  theme_statebins()
sb

This code creates a dataframe dat with the state abbreviations and values, and also adds a column lab that combines the state abbreviation and value. Then, it uses the statebins() function to create the statebin heatmap, and the geom_statebins_label() function with the aes(label = lab) argument to add the labels with the counts to each bin. Finally, it applies the theme_statebins() function to format the heatmap, and displays the resulting heatmap using sb.