Arrow

library(plotly)
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 4.3.3
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
# Sample data similar to the plot
data <- data.frame(
  group = c("White", "Hispanic", "Black"),
  percent_population = c(49, 35, 8),
  percent_injury = c(37, 42, 12)
)

# Create the dot plot
fig <- plot_ly(data, x = ~percent_population, y = ~group, type = 'scatter', mode = 'markers',
               marker = list(color = 'blue', size = 40),
               name = 'Percent of Population') %>%
  add_trace(x = ~percent_injury, y = ~group, type = 'scatter', mode = 'markers',
            marker = list(color = 'red', size = 40),
            name = 'Percent Killed or Incapacitated Injury') %>%
  layout(
    xaxis = list(title = ""),
    yaxis = list(title = "", tickvals = data$group, ticktext = data$group, tickmode = 'array'),
    annotations = list(
      list(
        x = data$percent_population[1], 
        y = data$group[1], 
        text = "49%", 
        xref = "x", 
        yref = "y", 
        showarrow = FALSE,
        font = list(size = 14, color = "white")
      ),
      list(
        x = data$percent_population[2], 
        y = data$group[2], 
        text = "35%", 
        xref = "x", 
        yref = "y", 
        showarrow = FALSE,
        font = list(size = 14, color = "white")
      ),
      list(
        x = data$percent_population[3], 
        y = data$group[3], 
        text = "8%", 
        xref = "x", 
        yref = "y", 
        showarrow = FALSE,
        font = list(size = 14, color = "white")
      ),
      list(
        x = data$percent_injury[1], 
        y = data$group[1], 
        text = "37%", 
        xref = "x", 
        yref = "y", 
        showarrow = FALSE,
        font = list(size = 14, color = "white")
      ),
      list(
        x = data$percent_injury[2], 
        y = data$group[2], 
        text = "42%", 
        xref = "x", 
        yref = "y", 
        showarrow = FALSE,
        font = list(size = 14, color = "white")
      ),
      list(
        x = data$percent_injury[3], 
        y = data$group[3], 
        text = "12%", 
        xref = "x", 
        yref = "y", 
        showarrow = FALSE,
        font = list(size = 14, color = "white")
      ),
      list(
        x = data$percent_injury[1] + 2,
        y = data$group[1],
        ax = data$percent_population[1] - 2,
        ay = data$group[1],
        xref = "x",
        yref = "y",
        axref = "x",
        ayref = "y",
        showarrow = TRUE,
        arrowhead = 2,
        arrowsize = 2,
        arrowcolor = 'grey'
      ),
      list(
        x = data$percent_injury[2] - 2,
        y = data$group[2],
        ax = data$percent_population[2] + 2,
        ay = data$group[2],
        xref = "x",
        yref = "y",
        axref = "x",
        ayref = "y",
        showarrow = TRUE,
        arrowhead = 2,
        arrowsize = 2,
        arrowcolor = 'grey'
      ),
      list(
        x = data$percent_injury[3] - 1,
        y = data$group[3],
        ax = data$percent_population[3] + 1,
        ay = data$group[3],
        xref = "x",
        yref = "y",
        axref = "x",
        ayref = "y",
        showarrow = TRUE,
        arrowhead = 2,
        arrowsize = 2,
        arrowcolor = 'grey'
      )
    ),
    legend = list(orientation = 'h', x = 0.1, y = -0.1)
  )

fig