I am working on a risk matrix that shows a count of issues identified using qualitative data analysis using dplyr and ggplot2. However, when I attempt to dplyr::left_join() my count data to a grid specifying positions and colors, a few of the counts are dropped.
Can someone explain to me why the rows in df_n with counts higher than 1 or 2 seem to get dropped when merged into df_plot? Thanks!
library(tidyverse)
df_n <- structure(list(frequency = c(0.3, 0.3, 0.3, 0.5, 0.5, 0.5, 0.7, 
0.7, 0.7, 0.7, 0.9, 0.9, 0.9), criticality = c(30, 70, 90, 10, 
30, 50, 30, 50, 70, 90, 50, 70, 90), inefficiency = c(9, 21, 
27, 5, 15, 25, 21, 35, 49, 63, 45, 63, 81), color = c("green", 
"green", "yellow", "green", "green", "yellow", "green", "yellow", 
"red", "red", "yellow", "red", "red"), n = c(1L, 1L, 1L, 1L, 
1L, 1L, 4L, 2L, 5L, 2L, 1L, 2L, 1L)), row.names = c(NA, -13L), class = c("tbl_df", 
"tbl", "data.frame"))
df_color <- structure(list(frequency = c(0.1, 0.1, 0.1, 0.1, 0.1, 0.3, 0.3, 
0.3, 0.3, 0.3, 0.5, 0.5, 0.5, 0.5, 0.5, 0.7, 0.7, 0.7, 0.7, 0.7, 
0.9, 0.9, 0.9, 0.9, 0.9), criticality = c(10, 30, 50, 70, 90, 
10, 30, 50, 70, 90, 10, 30, 50, 70, 90, 10, 30, 50, 70, 90, 10, 
30, 50, 70, 90), inefficiency = c(1, 3, 5, 7, 9, 3, 9, 15, 21, 
27, 5, 15, 25, 35, 45, 7, 21, 35, 49, 63, 9, 27, 45, 63, 81), 
    color = c("green", "green", "green", "green", "green", "green", 
    "green", "green", "green", "yellow", "green", "green", "yellow", 
    "yellow", "yellow", "green", "green", "yellow", "red", "red", 
    "green", "yellow", "yellow", "red", "red")), row.names = c(NA, 
-25L), class = c("tbl_df", "tbl", "data.frame"))
df_plot <- df_color %>%
dplyr::left_join(df_n, by = c("frequency", "criticality", "inefficiency", "color"))  
  ggplot2::ggplot(data = df_plot, ggplot2::aes(x = frequency, y = criticality, fill = color)) +
  ggplot2::geom_tile(color = "white", lwd = 1.5, linetype = 1) +
  ggplot2::scale_fill_identity() +
    ggplot2::geom_text(aes(label = n, fontface = "bold")) +
  ggplot2::theme_classic()
