Skip to content

facet_widths not setting facet widths #685

@js-wur

Description

@js-wur

After switching to a new machine and starting with a fresh install of R/RStudio I haven't been able to set facet widths. The example from the documentation also failsto set facet widths:

library(ggplot2)
library(ggtree)
library(reshape2)

set.seed(123)
tree <- rtree(30)

p <- ggtree(tree, branch.length = "none") + 
  geom_tiplab() + theme(legend.position='none')

a <- runif(30, 0,1)
b <- 1 - a
df <- data.frame(tree$tip.label, a, b)
df <- melt(df, id = "tree.tip.label")

p2 <- p + geom_facet(panel = 'bar', data = df, geom = geom_bar, 
                     mapping = aes(x = value, fill = as.factor(variable)), 
                     orientation = 'y', width = 0.8, stat='identity') + 
  xlim_tree(9)

facet_widths(p2, widths = c(1, 2))

I get a warning message:

Warning message:
In x[i] <- value :
  number of items to replace is not a multiple of replacement length

..and a plot in which the widths of the facets equal.
Is this something that's unique to my setup, or is this a more general problem?

sessionInfo``` R version 4.5.2 (2025-10-31 ucrt) Platform: x86_64-w64-mingw32/x64 Running under: Windows 11 x64 (build 26100) Matrix products: default LAPACK version 3.12.1 locale: [1] LC_COLLATE=English_United Kingdom.utf8 LC_CTYPE=English_United Kingdom.utf8 LC_MONETARY=English_United Kingdom.utf8 LC_NUMERIC=C [5] LC_TIME=English_United Kingdom.utf8 time zone: Europe/Amsterdam tzcode source: internal attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] reshape2_1.4.5 ggtree_4.0.1 ggplot2_4.0.1 loaded via a namespace (and not attached): [1] yulab.utils_0.2.1 rappdirs_0.3.3 generics_0.1.4 tidyr_1.3.1 fontLiberation_0.1.0 ggplotify_0.1.3 [7] stringi_1.8.7 lattice_0.22-7 digest_0.6.39 magrittr_2.0.4 grid_4.5.2 RColorBrewer_1.1-3 [13] fastmap_1.2.0 plyr_1.8.9 jsonlite_2.0.0 ape_5.8-1 BiocManager_1.30.27 purrr_1.2.0 [19] aplot_0.2.9 scales_1.4.0 fontBitstreamVera_0.1.1 lazyeval_0.2.2 cli_3.6.5 rlang_1.1.6 [25] fontquiver_0.2.1 tidytree_0.4.6 withr_3.0.2 gdtools_0.4.4 tools_4.5.2 parallel_4.5.2 [31] dplyr_1.1.4 vctrs_0.6.5 R6_2.6.1 gridGraphics_0.5-1 lifecycle_1.0.4 stringr_1.6.0 [37] fs_1.6.6 htmlwidgets_1.6.4 ggfun_0.2.0 treeio_1.34.0 pkgconfig_2.0.3 pillar_1.11.1 [43] gtable_0.3.6 glue_1.8.0 Rcpp_1.1.0 systemfonts_1.3.1 tibble_3.3.0 tidyselect_1.2.1 [49] ggiraph_0.9.2 farver_2.1.2 htmltools_0.5.8.1 nlme_3.1-168 patchwork_1.3.2 labeling_0.4.3 [55] compiler_4.5.2 S7_0.2.1 ```

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions