Open igordot opened 5 months ago
Upgrading from ggplot2 3.4.x -> 3.5.0 caused this .. I raised an issue on their github repo. hopefully they fix it soon.
Thanks for the update! I had some other packages break with ggplot2 3.5.0 as well.
Hi, I just stumbled across this by accident.
This is intended, and ggplot2 is not going to remedy this issue.
If you want to include all keys of a layer regardless of whether that value is present in the data, you should use show.legend = TRUE
.
By default, only keys are shown for which values exist in the data.
Curiously, I've seen some packages add specific workarounds related to ggplot2 3.5, so it's definitely a widespread issue without a simple elegant fix. For example, hrbrthemes (with over 1k GitHub stars): https://github.com/hrbrmstr/hrbrthemes/blob/6417996c2931b3fa84102b5034a42a920c91fdb9/R/color.r#L20-L23
The code you linked to is to silence soft-deprecation warnings, which is unrelated to legend keys. The way to restore old behaviour is to use show.legend
argument in layers, which is simple enough.
As an illustration of the fix proposed by @teunbrand and as a possible workaround one can manually set show.legend=TRUE
for the geom_point
layer like so:
library(numbat)
#> Loading required package: Matrix
library(dplyr, warn=FALSE)
nb <- readRDS(url("http://pklab.med.harvard.edu/teng/data/nb_TNBC1.rds"))
p <- nb$bulk_clones %>%
filter(n_cells > 50) %>%
plot_bulks(
min_LLR = 10, # filtering CNVs by evidence
legend = TRUE
)
for (i in seq_along(p)) {
p[[i]]$layers[[2]]$show.legend <- TRUE
}
p
Created on 2024-09-08 with reprex v2.1.1
It seems that the bulk_clones plot is sometimes missing the CNV state colors legend. Is that expected or a bug?
For example, here is the plot from the mouse tutorial with a proper legend:![image](https://github.com/kharchenkolab/numbat/assets/6363505/d56a5e88-41e6-4705-91ae-eb09d2de37ab)
Compare that to the Interpreting Numbat results vignette where the legend only has two colors:![image](https://github.com/kharchenkolab/numbat/assets/6363505/284d0aec-64f2-4faa-9940-98844dd41ae1)