0

My question is basically a duplicate of Width of boxplot created from summary stats which has only received poor attention because of incomplete tagging (no rnor ggplot2 tag), I have suggested some edits accordingly.

I tried to reproduce the example of this question, and I got

Warning: Ignoring unknown parameters: width

I found this fairly curious, as I have used width as a parameter before. The warning disappeared when removing stat = identity

In plenty of previous threads, this parameter seemed to have worked (e.g.: Fine tuning ggplot2's geom boxplot). Is this related to the upgrade to ggplot2 3.0?

of note
I don't really want to use pre-computed values for box plots, I just came across this issue when starting to answer the above mentioned question.


sessionInfo()
R version 3.5.0 (2018-04-23)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.6

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] ggplot2_3.0.0

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.17     digest_0.6.15    withr_2.1.2      dplyr_0.7.6     
 [5] assertthat_0.2.0 grid_3.5.0       plyr_1.8.4       R6_2.2.2        
 [9] gtable_0.2.0     magrittr_1.5     scales_0.5.0     pillar_1.2.3    
[13] rlang_0.2.2      lazyeval_0.2.1   bindrcpp_0.2.2   labeling_0.3    
[17] tools_3.5.0      glue_1.2.0       purrr_0.2.5      munsell_0.5.0   
[21] yaml_2.1.19      compiler_3.5.0   pkgconfig_2.0.1  colorspace_1.3-2
[25] tidyselect_0.2.4 bindr_0.1.1      tibble_1.4.2  
tjebo
  • 21,977
  • 7
  • 58
  • 94

1 Answers1

2

I can confirm this (odd?) behaviour.

For example, if we do

ggplot(DF) +
    geom_boxplot(
        aes(x = x, ymin = min, lower = low, middle = mid, upper = top, ymax = max, width = 0.1),
        stat = "identity", fill = "cornflowerblue")

we get a warning

Warning: Ignoring unknown aesthetics: width

but it actually does change the width

enter image description here

If you move the width = 0.1 outside of aes you get a warning and the width does not change.

Comments from a related post ggplot - width of boxplot from summary stats [duplicate] suggest that this wasn't always the case.


Sample data

DF <- data.frame(
    x = c("2012","2016"),
    min = c(29.9,37.0),
    low = c(64.0,58.0),
    mid = c(108.0,73.0),
    top = c(168.0,108.0),
    max = c(258.0,199.0))
Maurits Evers
  • 49,617
  • 4
  • 47
  • 68
  • Interesting - I hadn't thought of putting `width` into the `aes`-call. In the meanwhile I found [this issue report on GitHub](https://github.com/tidyverse/ggplot2/issues/2893) which was posted a few hours earlier. Funny how somethings things coincide... – tjebo Sep 18 '18 at 06:56
  • 1
    @Tjebo Interesting find. Based on the older [SO post](https://stackoverflow.com/questions/48808447/ggplot-width-of-boxplot-from-summary-stats) I gather that at some point `width` did in fact work as expected. I saw your comment on the GH issue (you got the right ping btw, thanks;-). Curious to hear what the devs say. – Maurits Evers Sep 18 '18 at 12:27
  • FYI :) https://github.com/tidyverse/ggplot2/issues/2893#event-1855090837 – tjebo Sep 19 '18 at 19:29