-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Closed
Description
The current method for rendering legends inside the plot does not appear to work with the "viridis" colour scale options. Using this approach results in the scale bar being rendered as points, whereas the depeciated method as expected. Please see the code below for an example. Note that my R is a bit outdated but I updated ggplot for this bug report, hence the warning after calling tidyverse.
library(tidyverse)
#> Warning: package 'ggplot2' was built under R version 4.4.3
#Regular scale, outside of plot area
mtcars %>%
ggplot(aes(cyl, mpg, col = hp)) +
geom_point() +
scale_colour_viridis_c() #Inside scale using current approach
mtcars %>%
ggplot(aes(cyl, mpg, col = hp)) +
geom_point() +
scale_colour_viridis_c() +
guides(colour = guide_legend(position = "inside")) +
theme(legend.position.inside = c(0.9, 0.8))#Inside scale using depreciated approach
mtcars %>%
ggplot(aes(cyl, mpg, col = hp)) +
geom_point() +
scale_colour_viridis_c() +
theme(legend.position = c(0.9, 0.8))Created on 2025-10-22 with reprex v2.1.1
Session info
sessionInfo()
#> R version 4.4.1 (2024-06-14 ucrt)
#> Platform: x86_64-w64-mingw32/x64
#> Running under: Windows 11 x64 (build 22631)
#>
#> Matrix products: default
#>
#>
#> locale:
#> [1] LC_COLLATE=English_United States.utf8
#> [2] LC_CTYPE=English_United States.utf8
#> [3] LC_MONETARY=English_United States.utf8
#> [4] LC_NUMERIC=C
#> [5] LC_TIME=English_United States.utf8
#>
#> time zone: America/Los_Angeles
#> tzcode source: internal
#>
#> attached base packages:
#> [1] stats graphics grDevices utils datasets methods base
#>
#> other attached packages:
#> [1] lubridate_1.9.3 forcats_1.0.0 stringr_1.5.1 dplyr_1.1.4
#> [5] purrr_1.0.2 readr_2.1.5 tidyr_1.3.1 tibble_3.2.1
#> [9] ggplot2_4.0.0 tidyverse_2.0.0
#>
#> loaded via a namespace (and not attached):
#> [1] gtable_0.3.6 compiler_4.4.1 reprex_2.1.1 tidyselect_1.2.1
#> [5] xml2_1.3.6 scales_1.4.0 yaml_2.3.10 fastmap_1.2.0
#> [9] R6_2.5.1 labeling_0.4.3 generics_0.1.3 curl_5.2.3
#> [13] knitr_1.50 pillar_1.9.0 RColorBrewer_1.1-3 tzdb_0.4.0
#> [17] rlang_1.1.4 utf8_1.2.4 stringi_1.8.4 xfun_0.53
#> [21] fs_1.6.4 S7_0.2.0 viridisLite_0.4.2 timechange_0.3.0
#> [25] cli_3.6.3 withr_3.0.1 magrittr_2.0.3 digest_0.6.37
#> [29] grid_4.4.1 rstudioapi_0.16.0 hms_1.1.3 lifecycle_1.0.4
#> [33] vctrs_0.6.5 evaluate_1.0.0 glue_1.7.0 farver_2.1.2
#> [37] fansi_1.0.6 rmarkdown_2.28 tools_4.4.1 pkgconfig_2.0.3
#> [41] htmltools_0.5.8.1Metadata
Metadata
Assignees
Labels
No labels


