r - (函数(el,elname): "plot.title.position" is not a valid theme element name 中出现错误

标签 r ggplot2

我正在尝试使用 plot.title.position ggplot 中的参数如下所示

library(dplyr)

iris %>% 
  filter(Sepal.Length > 5.5) %>% 
  group_by(Species) %>% 
  summarise(n=n()) %>% 
  ggplot(aes(x=Species, y=n)) +
  geom_col()  +
  ggtitle("Long Sepal Iris by Species") +
  theme(axis.title.x=element_blank(),
        axis.title.y=element_blank(),
        plot.title.position = "plot") 

但是我明白了

Error in (function (el, elname)  : 
"plot.title.position" is not a valid theme element name.

ggplot2 manual

plot.title.position, plot.caption.position

Alignment of the plot title/subtitle and caption. The setting for plot.title.position applies to both the title and the subtitle. A value of "panel" (the default) means that titles and/or caption are aligned to the plot panels. A value of "plot" means that titles and/or caption are aligned to the entire plot (minus any space for margins and plot tag).

注释

> packageVersion('ggplot2')
[1] ‘3.2.1’

还有

> sessionInfo()
R version 3.6.2 (2019-12-12)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Mojave 10.14.1

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib

locale:
[1] en_AU.UTF-8/en_AU.UTF-8/en_AU.UTF-8/C/en_AU.UTF-8/en_AU.UTF-8

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

other attached packages:
 [1] wordcloud2_0.2.1  scales_1.0.0      forcats_0.4.0     stringr_1.4.0     purrr_0.3.3       readr_1.3.1      
 [7] tidyr_1.0.0       tibble_2.1.3      tidyverse_1.2.1   dplyr_0.8.99.9002 ggplot2_3.2.1    

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.4           lubridate_1.7.4      lattice_0.20-38      prettyunits_1.0.2    ps_1.3.0            
 [6] assertthat_0.2.1     digest_0.6.25        R6_2.4.1             cellranger_1.1.0     backports_1.1.5     
[11] stats4_3.6.2         httr_1.4.1           pillar_1.4.3         rlang_0.4.5.9000     lazyeval_0.2.2      
[16] readxl_1.3.1         rstudioapi_0.10      data.table_1.12.2    callr_3.2.0          Matrix_1.2-18       
[21] labeling_0.3         loo_2.2.0            htmlwidgets_1.3      munsell_0.5.0        broom_0.5.2         
[26] compiler_3.6.2       modelr_0.1.4         xfun_0.12            rstan_2.19.2         pkgconfig_2.0.3     
[31] pkgbuild_1.0.3       htmltools_0.3.6      tidyselect_1.0.0     gridExtra_2.3        matrixStats_0.55.0  
[36] fansi_0.4.1          viridisLite_0.3.0    crayon_1.3.4         withr_2.1.2          grid_3.6.2          
[41] nlme_3.1-142         jsonlite_1.6.1       gtable_0.3.0         lifecycle_0.2.0      magrittr_1.5        
[46] StanHeaders_2.21.0-1 cli_2.0.2            stringi_1.4.6        xml2_1.2.2           ellipsis_0.3.0      
[51] generics_0.0.2       vctrs_0.2.99.9010    RColorBrewer_1.1-2   tools_3.6.2          Cairo_1.5-10        
[56] glue_1.3.2           hms_0.4.2            yaml_2.2.1           parallel_3.6.2       processx_3.3.0      
[61] inline_0.3.15        colorspace_1.4-1     rvest_0.3.4          plotly_4.9.0         knitr_1.27.2        
[66] haven_2.1.1 

最佳答案

对于其他人,只需确保您至少安装了 ggplot2 版本 3.3.0 即可。

您可以检查

packageVersion("ggplot2")
[1] ‘3.3.0’

如果少于此值,只需 install.packages("ggplot2", dependency=TRUE) 即可确保您处于最新状态

关于r - (函数(el,elname): "plot.title.position" is not a valid theme element name 中出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60909894/

相关文章:

r - 与 r 中的缺失或错误组合

r - ggplot2:用于标记多个 geom_abline 斜率的图例

r - 按颜色对 ggplot facet_wrap 进行排序?

r - Shiny 没有像我期望的那样显示我的 ggplot

r - 使用 ggcontour 在数据集上覆盖树

r - ggplot边距 - 改变到轴的距离

r - 关键字在 R 中字符串的上下文中重复多次

r - 如何将 Shiny 的 input$ID 变量传递给 dplyr 函数参数

regex - 当连字符围绕单个内部字符时如何替换词内连字符

r - 合并 R 中的列(dplyr 或任何其他包)