Skip to content

Error setting width in update_geom_defaults() #2245

Closed

Description

@bschneidr

Using update_geom_defaults(), I want to update the default width of geom_bar() (and its cousin geom_col(), too).

Using update_geom_default() to do so, I don't run into any issue until I try to actually call geom_bar(), whereupon I receive the error message #> Error: Aesthetics must be either length 1 or the same as the data (3): width.

In contrast, as can be seen in the reprex below, specifying width manually in geom_bar() works correctly.

library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(ggplot2)

# Update default width
update_geom_defaults(geom = 'bar',
                     new = list(width = 0.5))

# Attempt to plot with geom_bar
iris %>% 
  count(Species) %>% 
  ggplot(aes(x = Species, y = n)) +
  geom_bar(stat = 'identity')
#> Error: Aesthetics must be either length 1 or the same as the data (3): width

# Plot with manual specification of width
iris %>% 
  count(Species) %>% 
  ggplot(aes(x = Species, y = n)) +
  geom_bar(stat = 'identity', width = 0.5)
Session info
devtools::session_info()
#> Session info -------------------------------------------------------------
#>  setting  value                       
#>  version  R version 3.4.1 (2017-06-30)
#>  system   x86_64, mingw32             
#>  ui       RTerm                       
#>  language (EN)                        
#>  collate  English_United States.1252  
#>  tz       America/New_York            
#>  date     2017-08-22
#> Packages -----------------------------------------------------------------
#>  package    * version  date       source        
#>  assertthat   0.2.0    2017-04-11 CRAN (R 3.3.3)
#>  backports    1.1.0    2017-05-22 CRAN (R 3.4.0)
#>  base       * 3.4.1    2017-06-30 local         
#>  bindr        0.1      2016-11-13 CRAN (R 3.3.2)
#>  bindrcpp     0.2      2017-06-17 CRAN (R 3.4.0)
#>  bitops       1.0-6    2013-08-17 CRAN (R 3.3.2)
#>  colorspace   1.3-2    2016-12-14 CRAN (R 3.3.2)
#>  compiler     3.4.1    2017-06-30 local         
#>  datasets   * 3.4.1    2017-06-30 local         
#>  devtools     1.13.3   2017-08-02 CRAN (R 3.4.1)
#>  digest       0.6.12   2017-01-27 CRAN (R 3.3.2)
#>  dplyr      * 0.7.2    2017-07-20 CRAN (R 3.4.1)
#>  evaluate     0.10.1   2017-06-24 CRAN (R 3.4.0)
#>  ggplot2    * 2.2.1    2016-12-30 CRAN (R 3.4.0)
#>  glue         1.1.1    2017-06-21 CRAN (R 3.4.0)
#>  graphics   * 3.4.1    2017-06-30 local         
#>  grDevices  * 3.4.1    2017-06-30 local         
#>  grid         3.4.1    2017-06-30 local         
#>  gtable       0.2.0    2016-02-26 CRAN (R 3.3.1)
#>  htmltools    0.3.6    2017-04-28 CRAN (R 3.4.0)
#>  knitr        1.17     2017-08-10 CRAN (R 3.4.1)
#>  labeling     0.3      2014-08-23 CRAN (R 3.3.1)
#>  lazyeval     0.2.0    2016-06-12 CRAN (R 3.3.2)
#>  magrittr     1.5      2014-11-22 CRAN (R 3.3.1)
#>  memoise      1.1.0    2017-04-21 CRAN (R 3.3.3)
#>  methods    * 3.4.1    2017-06-30 local         
#>  munsell      0.4.3    2016-02-13 CRAN (R 3.3.1)
#>  pkgconfig    2.0.1    2017-03-21 CRAN (R 3.4.0)
#>  plyr         1.8.4    2016-06-08 CRAN (R 3.3.0)
#>  R6           2.2.2    2017-06-17 CRAN (R 3.4.0)
#>  Rcpp         0.12.12  2017-07-15 CRAN (R 3.4.1)
#>  RCurl        1.95-4.8 2016-03-01 CRAN (R 3.3.1)
#>  rlang        0.1.2    2017-08-09 CRAN (R 3.4.1)
#>  rmarkdown    1.6      2017-06-15 CRAN (R 3.4.0)
#>  rprojroot    1.2      2017-01-16 CRAN (R 3.3.2)
#>  scales       0.4.1    2016-11-09 CRAN (R 3.3.2)
#>  stats      * 3.4.1    2017-06-30 local         
#>  stringi      1.1.5    2017-04-07 CRAN (R 3.3.3)
#>  stringr      1.2.0    2017-02-18 CRAN (R 3.3.2)
#>  tibble       1.3.3    2017-05-28 CRAN (R 3.4.0)
#>  tools        3.4.1    2017-06-30 local         
#>  utils      * 3.4.1    2017-06-30 local         
#>  withr        2.0.0    2017-07-28 CRAN (R 3.4.1)
#>  XML          3.98-1.9 2017-06-19 CRAN (R 3.4.0)
#>  yaml         2.1.14   2016-11-12 CRAN (R 3.3.2)

Activity

  1. added
    bug
    on Aug 24, 2017
  2. hadley commented on Oct 30, 2017

    @hadley
    Member

    Unfortunately you can't override the default width due to the way it's calculated.

  3. locked as resolved and limited conversation to collaborators on Jun 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    buglayers 📈

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions