tidyverse / ggplot2

An implementation of the Grammar of Graphics in R
https://ggplot2.tidyverse.org
Other
6.51k stars 2.03k forks source link

color gets "stuck" after having a typo in color names #1870

Closed zx8754 closed 8 years ago

zx8754 commented 8 years ago

Here is an example:

library(ggplot2)  # ggplot2_2.1.0  R version 3.3.1 (2016-06-21)

p5 <- ggplot(mtcars, aes(x = mpg, y = disp, color = gear)) +
  geom_point()

# add themes with "typo" color name
p5 + theme_minimal() + theme(text = element_text(color = "x"))
# Error in grid.Call(L_textBounds, as.graphicsAnnot(x$label), x$x, x$y,  : 
#   invalid color name 'x'

# fix the color name to "red" - same error for color x from above again...
p5 + theme_minimal() + theme(text = element_text(color="red"))
# Error in grid.newpage() : invalid color name 'x'

# As p5 is not updated with themes because of errors,
#   it should still plot, but it gives error again...
p5
# Error in grid.newpage() : invalid color name 'x'

# OK, let's forget about p5... still error
ggplot(mtcars, aes(x = mpg, y = disp, color = gear)) +
  geom_point()
# Error in grid.newpage() : invalid color name 'x'

Only after restarting R, I can use ggplot again, here is related SO post:

# sessionInfo()
#
# R version 3.3.1 (2016-06-21)
# Platform: x86_64-w64-mingw32/x64 (64-bit)
# Running under: Windows 7 x64 (build 7601) Service Pack 1
# 
# locale:
#   [1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United Kingdom.1252   
# [3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C                           
# [5] LC_TIME=English_United Kingdom.1252    
# 
# attached base packages:
#   [1] stats     graphics  grDevices utils     datasets  methods   base     
# 
# other attached packages:
#   [1] ggplot2_2.1.0
# 
# loaded via a namespace (and not attached):
#   [1] labeling_0.3     colorspace_1.2-7 scales_0.4.0     plyr_1.8.4       tools_3.3.1      gtable_0.2.0    
# [7] Rcpp_0.12.7      grid_3.3.1       digest_0.6.10    munsell_0.4.3   
hadley commented 8 years ago

Unlikely to be a bug in ggplot2. Just close your graphics devices if it continues to be a problem.