r - 升级到 2.0 版后 ggplot2 错误

标签 r ggplot2

我有一些代码在升级到最新的 ggplot2 版本后不再有效。它从 12 月初就发布了,我想知道是否还有其他人遇到同样的问题。

以下代码曾经完美运行:

gLM1 <- ggplot(data = raw.data, aes(x = predict.lm1, y = (Sales_C-predict.lm1))) +
geom_point(alpha = I(0.75), colour = myPal[1]) +
geom_smooth(span = 0.75, degree = 1, size = 1.25, se = FALSE, colour = myPal[5]) +
labs(list(title = "Fitted vs Residuals", x = "Fitted Values", y = "Residuals")) +
theme_bw() + myGgTheme
gLM1

现在突然返回这个:

Error: Unknown parameters: degree

如果我从 geom_smooth 中删除 degree 参数,它会再次起作用。 同样,这段代码曾经运行但现在失败了:

gclus <- ggplot(data = raw.data, aes(x = oOrollingSD, y = OnTarget, colour = clusterGroup, size = Quota)) +
xlim(4.2, 11.8) +
geom_point(alpha = I(0.75)) +
geom_vline(x = 7.8, linetype = "dashed", colour = myPal[3]) +
scale_colour_manual(values = myPalContrasts[c(7,3,4)]) +
theme_bw() + myGgThemeSilentX
gclus

错误是

Error: Unknown parameters: x

如果我删除 geom_vline 它会再次工作(我不能简单地删除这里的 x 参数,因为它是 vline 位置的原因!

直到昨天,所有这些代码都可以正常工作。在准备报告的最后几周里,我确实运行了数十次。我阅读了有关 ggplot2 的最新版本并于昨天对其进行了更新,但出现了这些错误。

我的 ggplot2 版本是 2.0,我的所有其他 session 信息都在下面。我不记得我之前使用的是什么 ggplot2 版本:

R version 3.2.2 (2015-08-14)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 8 x64 (build 9200)

locale:
[1] LC_COLLATE=English_Singapore.1252 
[2] LC_CTYPE=English_Singapore.1252   
[3] LC_MONETARY=English_Singapore.1252
[4] LC_NUMERIC=C                      
[5] LC_TIME=English_Singapore.1252    

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

other attached packages:
[1] dplyr_0.4.3     readr_0.1.1     stringr_1.0.0  
[4] knitr_1.11      ggplot2_2.0.0   lattice_0.20-33

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.1      digest_0.6.8     assertthat_0.1  
 [4] R6_2.1.1         grid_3.2.2       plyr_1.8.3      
 [7] gtable_0.1.2     DBI_0.3.1        magrittr_1.5    
[10] scales_0.3.0     highr_0.5.1      stringi_0.5-5   
[13] lazyeval_0.1.10  curl_0.9.3       rmarkdown_0.8.1 
[16] labeling_0.3     tools_3.2.2      munsell_0.4.2   
[19] parallel_3.2.2   colorspace_1.2-6 htmltools_0.2.6 

最佳答案

来自文档,

1- 使用method.args 将更多参数传递给建模函数

ggplot(mpg, aes(displ, hwy)) +
 geom_point() +
 geom_smooth(method = "loess", method.args=list(degree=2))

2- 相关的美学是 xintercept

ggplot(mtcars, aes(wt, mpg)) + geom_point() + 
  geom_vline(xintercept = 5)

关于r - 升级到 2.0 版后 ggplot2 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34866026/

相关文章:

r - 在 ggplot2 中使用带有百分号 (%) 的 plotmath

删除ggplot2中x轴的空白行

r - 编辑grid.arrange标题的样式。粗体,斜体等R

r - R : argument is not numeric or logical: returning NA, as.integer()

rstudioapi askForPassword 不屏蔽用户名输入

r - 使用 R,从网络导入数据

r - qqplot + stat_smooth 错误

r - 在 ggplot2 图表中实现谷歌字体

r - rmr2 mapreduce始终为$ key和$ val生成NULL

r - 按分位数计算值的总和