My goal is to take two data frames, find differences between them and highlight the cells which are different. I currently have a working solution that colors whole rows that are different but I would like only specific cells that are different to be highlighted. Here is my data frame (The pictures of the data frames show different column names. This is not how it is supposed to be but if you take my code for the data frames and run it you will not run into this issue)
response <- c("Best overall", "Best overall", "Best overall", "Best overall", "Best overall", "Best overall", "Diease control", "Diease control", "Observed response", "Observed respone")
value <- c("cr", "pr", "sd", "pd", "NE", "NA", "yes", "no", "yes", "no")
drug <- c(0, 0, 2, 10, 0, 0, 0, 12, 2, 10)
ex_df <- data.frame(response, value)
ex_df <- data.frame(ex_df, drug)
response <- c("Best overall", "Best overall", "Best overall", "Best overall", "Best overall", "Best overall", "Diease control", "Diease control", "Observed response", "Observed respone")
value <- c("cr", "pr", "sd", "pd", "NE", "NA", "yes", "no", "yes", "no")
drug <- c(0, 0, 5, 9, 0, 0, 0, 11, 2, 10)
ex1_df <- data.frame(response, value)
ex1_df <- data.frame(ex1_df, drug)
The only thing I want colored here are the cells under drug that differ from the cells under drug in the first data frame. So in the data frame containing drug1, I want cells containing values 5, 9, and 11 to be colored a light red. My attempt uses anti_join:
missing <- ex1_df %>%
anti_join(ex_df) %>%
mutate(missing = TRUE)
ex_diff <- ex1_df %>%
left_join(missing) %>%
gt(rowname_col = "row", groupname_col = "group") %>%
tab_style(style = list(cell_fill(color = "lightpink")),
locations = cells_body(columns = everything(), rows = missing)) %>%
cols_hide(missing)
ex_diff
This gives the output with the whole rows highlighted but I would like to only highlight the cells that the different numbers are in.
Any help would be great!


