Skip to content

Commit 54d5fe7

Browse files
fix(plot_serocurve): suppress fill scale warning when show_ci = FALSE
Move `scale_fill_manual()` inside an `if (show_ci)` guard so it is only added when a CI ribbon is actually drawn. Previously the fill scale was applied unconditionally for single-stratification plots, producing "No shared levels found between names(values) of the manual scale and the data's fill values" when show_ci was FALSE — which triggered an R CMD check failure on the `serocurve-population-no-ci` test. Co-authored-by: Samuel Hisaji Schildhauer <sschildhauer@users.noreply.github.com>
1 parent bf221e2 commit 54d5fe7

1 file changed

Lines changed: 13 additions & 9 deletions

File tree

R/plot_serocurve.R

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -225,22 +225,26 @@ plot_serocurve <- function(
225225
color_vals <- c("median" = "red")
226226
color_labels <- c("median" = "Median")
227227

228-
fill_vals <- c("ci" = "red")
229-
fill_labels <- c("ci" = "95% credible interval")
230-
231228
p <- p +
232229
ggplot2::scale_color_manual(
233230
name = "",
234231
values = color_vals,
235232
labels = color_labels,
236233
guide = ggplot2::guide_legend(override.aes = list(shape = NA))
237-
) +
238-
ggplot2::scale_fill_manual(
239-
name = "",
240-
values = fill_vals,
241-
labels = fill_labels,
242-
guide = ggplot2::guide_legend(override.aes = list(color = NA))
243234
)
235+
236+
if (show_ci) {
237+
fill_vals <- c("ci" = "red")
238+
fill_labels <- c("ci" = "95% credible interval")
239+
240+
p <- p +
241+
ggplot2::scale_fill_manual(
242+
name = "",
243+
values = fill_vals,
244+
labels = fill_labels,
245+
guide = ggplot2::guide_legend(override.aes = list(color = NA))
246+
)
247+
}
244248
}
245249

246250
# ---- Faceting ----------------------------------------------------------

0 commit comments

Comments
 (0)