问题:
\n\n我尝试运行一个函数(ggwithinplot)来绘制 r 包 ggstatsplot 中的数据。但运行这个函数花了很长时间,什么结果也没有。
\n\n\n\n所以我在这个功能运行时关闭了它。我试着等待。它不起作用。所以这个问题不是时间问题。
\n\n之后我想知道是否是因为我得到了大量的数据点(N=2000)。因此我尝试了另一个包含 250 个数据点的样本。这次,我收到此错误:“错误:名称必须是唯一的。”
\n\nERROR: Names must be unique. Backtrace: \n1. ggstatsplot::ggwithinstats(...) \n27. vctrs:::validate_unique(names = names) \n28. vctrs:::stop_names_must_be_unique(which(duplicated(names))) \n29. vctrs:::stop_names(...) \n30. vctrs:::stop_vctrs(...)\nRun Code Online (Sandbox Code Playgroud)\n\n我检查了回溯:
\n\n33.stop(fallback)\n32.signal_abort(cnd)\n31.abort(message, class = c(class, "vctrs_error"), ...)\n30.stop_vctrs(message, class = c(class, "vctrs_error_names"), locations = locations, ...)\n29.stop_names("Names must be unique.", class = "vctrs_error_names_must_be_unique", locations = locations)\n28.stop_names_must_be_unique(which(duplicated(names)))\n27.validate_unique(names = names)\n26.vctrs::vec_as_names(names, repair = "check_unique")\n25.withCallingHandlers(expr, simpleError = function(cnd) { abort(conditionMessage(cnd), parent = cnd) })\n24.instrument_base_errors(expr)\n23.doTryCatch(return(expr), name, parentenv, handler)\n22.tryCatchOne(expr, names, parentenv, handlers[[1L]])\n21.tryCatchList(expr, classes, parentenv, handlers)\n20.tryCatch(instrument_base_errors(expr), vctrs_error_subscript = function(cnd) { cnd$subscript_action <- subscript_action(type) cnd$subscript_elt <- "column" cnd_signal(cnd) ...\n19.with_subscript_errors(vctrs::vec_as_names(names, repair = "check_unique"))\n18.rename_impl(NULL, .vars, quo(c(...)), strict = .strict)\n17.tidyselect::vars_rename(names(.data), !!!enquos(...))\n16.rename.data.frame(.data = ., variable = skim_variable)\n15.dplyr::rename(.data = ., variable = skim_variable)\n14.function_list[[k]](value)\n13.withVisible(function_list[[k]](value))\n12.freduce(value, `_function_list`)\n11.`_fseq`(`_lhs`)\n10.eval(quote(`_fseq`(`_lhs`)), env, env)\n9.eval(quote(`_fseq`(`_lhs`)), env, env)\n8.withVisible(eval(quote(`_fseq`(`_lhs`)), env, env))\n7.dplyr::left_join(x = df_results %>% dplyr::group_modify(.f = ~tibble::as_tibble(skimr::skim(purrr::keep(.x = ., .p = ..f))), keep = FALSE) %>% dplyr::ungroup(x = .), y = dplyr::tally(df_results), by = purrr::map_chr(.x = grouping.vars, .f = rlang::as_string)) %>% dplyr::mutate(.data = ., n = n - n_missing) %>% purrr::set_names(x = ., ...\n6.groupedstats::grouped_summary(data = data, grouping.vars = { { x } ...\n5.eval(lhs, parent, parent)\n4.eval(lhs, parent, parent)\n3.groupedstats::grouped_summary(data = data, grouping.vars = { { x } ...\n2.mean_labeller(data = data, x = { { x } ...\n1.ggwithinstats(data = emotion_rating_dt_50, x = variable, y = Emotion_rating, point.path = FALSE, mean.path = FALSE, effsize.type = "partial_eta", p.adjust.method = "fdr", ggtheme = theme_classic(), palette = "Darjeeling2", package = "wesanderson", ggstatsplot.layer = FALSE, xlab = "Dilemma types"\nRun Code Online (Sandbox Code Playgroud)\n\n我尝试过的:
\n\n代表
\n\nlibrary("tidyverse")\nlibrary("ggstatsplot")\n#> Registered S3 methods overwritten by \'broom.mixed\':\n#> method from \n#> augment.lme broom\n#> augment.merMod broom\n#> glance.lme broom\n#> glance.merMod broom\n#> glance.stanreg broom\n#> tidy.brmsfit broom\n#> tidy.gamlss broom\n#> tidy.lme broom\n#> tidy.merMod broom\n#> tidy.rjags broom\n#> tidy.stanfit broom\n#> tidy.stanreg broom\n#> Registered S3 methods overwritten by \'car\':\n#> method from\n#> influence.merMod lme4\n#> cooks.distance.influence.merMod lme4\n#> dfbeta.influence.merMod lme4\n#> dfbetas.influence.merMod lme4\nlibrary("bruceR")\n#> \xe8\xbd\xbd\xe5\x85\xa5\xe9\x9c\x80\xe8\xa6\x81\xe7\x9a\x84\xe7\xa8\x8b\xe8\xbe\x91\xe5\x8c\x85\xef\xbc\x9ario\n#> \xe8\xbd\xbd\xe5\x85\xa5\xe9\x9c\x80\xe8\xa6\x81\xe7\x9a\x84\xe7\xa8\x8b\xe8\xbe\x91\xe5\x8c\x85\xef\xbc\x9adata.table\n#> \n#> \xe8\xbd\xbd\xe5\x85\xa5\xe7\xa8\x8b\xe8\xbe\x91\xe5\x8c\x85\xef\xbc\x9a\'data.table\'\n#> The following objects are masked from \'package:dplyr\':\n#> \n#> between, first, last\n#> The following object is masked from \'package:purrr\':\n#> \n#> transpose\n#> \xe8\xbd\xbd\xe5\x85\xa5\xe9\x9c\x80\xe8\xa6\x81\xe7\x9a\x84\xe7\xa8\x8b\xe8\xbe\x91\xe5\x8c\x85\xef\xbc\x9apsych\n#> \n#> \xe8\xbd\xbd\xe5\x85\xa5\xe7\xa8\x8b\xe8\xbe\x91\xe5\x8c\x85\xef\xbc\x9a\'psych\'\n#> The following objects are masked from \'package:ggplot2\':\n#> \n#> %+%, alpha\n#> \xe8\xbd\xbd\xe5\x85\xa5\xe9\x9c\x80\xe8\xa6\x81\xe7\x9a\x84\xe7\xa8\x8b\xe8\xbe\x91\xe5\x8c\x85\xef\xbc\x9alubridate\n#> \n#> \xe8\xbd\xbd\xe5\x85\xa5\xe7\xa8\x8b\xe8\xbe\x91\xe5\x8c\x85\xef\xbc\x9a\'lubridate\'\n#> The following objects are masked from \'package:data.table\':\n#> \n#> hour, isoweek, mday, minute, month, quarter, second, wday, week,\n#> yday, year\n#> The following object is masked from \'package:base\':\n#> \n#> date\n#> \xe8\xbd\xbd\xe5\x85\xa5\xe9\x9c\x80\xe8\xa6\x81\xe7\x9a\x84\xe7\xa8\x8b\xe8\xbe\x91\xe5\x8c\x85\xef\xbc\x9aperformance\n#> Registered S3 methods overwritten by \'huge\':\n#> method from \n#> plot.sim BDgraph\n#> print.sim BDgraph\n#> Registered S3 method overwritten by \'GGally\':\n#> method from \n#> +.gg ggplot2\n#> ========================================================\n#> BRoadly Useful Collections and Extensions of R functions\n#> ========================================================\n#> Loaded packages:\n#> <U+2714> bruceR (version 0.4.0)\n#> <U+2714> rio, dplyr, data.table, psych, stringr, lubridate, performance, ggplot2\n#> Update:\n#> devtools::install_github("psychbruce/bruceR")\n#> Citation:\n#> Bao, H.-W.-S. (2020). bruceR: Broadly useful collections and extensions of R functions (version 0.4.0). Retrieved from https://github.com/psychbruce/bruceR\ndata <- import("E:/Zengxiaoyu/zxy_projcet/!ncov/data/Covid_Q1Q2data_minus200_0316.xlsx")\n#> New names:\n#> * hubei -> hubei...1396\ndata$hubei<-data$hubei...666\ndata$hubei <- as.factor(data$hubei)\n#data frame\nemotion_df <- data.frame(data$N1_disself,data$N1_disFAMI,data$N1_disHB,data$hubei)\n\nemotion_df <- as.data.table(emotion_df)\n\n#data preparation for repeated measure\n\nlong_emotion_rating_dt<-tidyr::pivot_longer(emotion_df, 1:3,names_to = \'variable\', values_to = "Emotion_rating")\n\nemotion_rating_dt_50<-subset(long_emotion_rating_dt,data.hubei=="HuBei")\n# to plot\ngrid::grid.newpage()\nggwithinstats(\n data = emotion_rating_dt_50,\n x = variable, # > 2 groups\n y = Emotion_rating,\n point.path = FALSE,\n mean.path = FALSE,\n effsize.type = \'partial_eta\' ,\n p.adjust.method = "fdr",\n ggtheme = theme_classic(),\n palette = "Darjeeling2",\n package = "wesanderson",\n ggstatsplot.layer = FALSE,\n xlab = "Dilemma types", \n ylab = "Emotion rating(1=appealing,7=appaling)",\n title = "Emotion rating for fout types moral dilemmas"\n)\n#> Note: 95% CI for effect size estimate was computed with 100 bootstrap samples.\n#> \n#> Error: Names must be unique.\nCreated on 2020-03-17 by the reprex package (v0.3.0)\nRun Code Online (Sandbox Code Playgroud)\n\n数据传输
\n\n\n\n会话信息
\n\nR version 3.6.3 (2020-02-29)\nPlatform: x86_64-w64-mingw32/x64 (64-bit)\nRunning under: Windows 10 x64 (build 15063)\n\nMatrix products: default\n\nlocale:\n[1] LC_COLLATE=Chinese (Simplified)_China.936 LC_CTYPE=Chinese (Simplified)_China.936 \n[3] LC_MONETARY=Chinese (Simplified)_China.936 LC_NUMERIC=C \n[5] LC_TIME=Chinese (Simplified)_China.936 \n\nattached base packages:\n[1] splines stats4 stats graphics grDevices utils datasets methods base \n\nother attached packages:\n [1] sessioninfo_1.1.1 reprex_0.3.0 reshape_0.8.8 gginnards_0.0.3 VGAM_1.1-2 parameters_0.6.0 \n [7] nnet_7.3-13 openxlsx_4.1.4 summarytools_0.9.6 ggcorrplot_0.1.3 bruceR_0.4.0 performance_0.4.4 \n[13] lubridate_1.7.4 psych_1.9.12.31 data.table_1.12.8 rio_0.5.16 ggstatsplot_0.3.1 forcats_0.5.0 \n[19] stringr_1.4.0 dplyr_0.8.5 purrr_0.3.3 readr_1.3.1 tidyr_1.0.2 tibble_2.1.3 \n[25] ggplot2_3.3.0 tidyverse_1.3.0 drawMap_0.1.0 \n\nloaded via a namespace (and not attached):\n [1] estimability_1.3 GGally_1.4.0 lavaan_0.6-5 coda_0.19-3 \n [5] acepack_1.4.1 knitr_1.28 multcomp_1.4-12 rpart_4.1-15 \n [9] inline_0.3.15 generics_0.0.2 callr_3.4.2 cowplot_1.0.0 \n [13] TH.data_1.0-10 xml2_1.2.5 httpuv_1.5.2 StanHeaders_2.21.0-1 \n [17] assertthat_0.2.1 d3Network_0.5.2.1 WRS2_1.0-0 xfun_0.12 \n [21] hms_0.5.3 evaluate_0.14 promises_1.1.0 fansi_0.4.1 \n [25] dbplyr_1.4.2 readxl_1.3.1 igraph_1.2.4.2 htmlwidgets_1.5.1 \n [29] DBI_1.1.0 Rsolnp_1.16 ellipsis_0.3.0 paletteer_1.1.0 \n [33] rcompanion_2.3.25 backports_1.1.5 pbivnorm_0.6.0 insight_0.8.2 \n [37] rapportools_1.0 libcoin_1.0-5 jmvcore_1.2.5 vctrs_0.2.4 \n [41] sjlabelled_1.1.3 abind_1.4-5 withr_2.1.2 pryr_0.1.4 \n [45] metaBMA_0.6.2 checkmate_2.0.0 bdsmatrix_1.3-4 emmeans_1.4.5 \n [49] fdrtool_1.2.15 prettyunits_1.1.1 fastGHQuad_1.0 mnormt_1.5-6 \n [53] cluster_2.1.0 mi_1.0 crayon_1.3.4 pkgconfig_2.0.3 \n [57] nlme_3.1-145 statsExpressions_0.3.1 palr_0.2.0 pals_1.6 \n [61] rlang_0.4.5 lifecycle_0.2.0 miniUI_0.1.1.1 groupedstats_0.2.0 \n [65] skimr_2.1 LaplacesDemon_16.1.4 MatrixModels_0.4-1 sandwich_2.5-1 \n [69] kutils_1.69 EMT_1.1 modelr_0.1.6 dichromat_2.0-0 \n [73] tcltk_3.6.3 cellranger_1.1.0 matrixStats_0.56.0 broomExtra_2.5.0 \n [77] lmtest_0.9-37 Matrix_1.2-18 regsem_1.5.2 loo_2.2.0 \n [81] mc2d_0.1-18 carData_3.0-3 boot_1.3-24 zoo_1.8-7 \n [85] base64enc_0.1-3 whisker_0.4 processx_3.4.2 png_0.1-7 \n [89] viridisLite_0.3.0 rjson_0.2.20 oompaBase_3.2.9 pander_0.6.3 \n [93] ggExtra_0.9 afex_0.26-0 multcompView_0.1-8 coin_1.3-1 \n [97] arm_1.10-1 jpeg_0.1-8.1 rockchalk_1.8.144 ggsignif_0.6.0 \n[101] scales_1.1.0 magrittr_1.5 plyr_1.8.6 compiler_3.6.3 \n[105] rstantools_2.0.0 bbmle_1.0.23.1 RColorBrewer_1.1-2 lme4_1.1-21 \n[109] cli_2.0.2 lmerTest_3.1-1 pbapply_1.4-2 ps_1.3.2 \n[113] TMB_1.7.16 Brobdingnag_1.2-6 htmlTable_1.13.3 Formula_1.2-3 \n[117] MASS_7.3-51.5 mgcv_1.8-31 tidyselect_1.0.0 stringi_1.4.6 \n[121] lisrelToR_0.1.4 sem_3.1-9 jtools_2.0.2 OpenMx_2.17.3 \n[125] latticeExtra_0.6-29 ggrepel_0.8.2 bridgesampling_1.0-0 grid_3.6.3 \n[129] tools_3.6.3 parallel_3.6.3 matrixcalc_1.0-3 rstudioapi_0.11 \n[133] foreign_0.8-76 gridExtra_2.3 ipmisc_1.2.0 pairwiseComparisons_0.2.5\n[137] BDgraph_2.62 digest_0.6.25 shiny_1.4.0.2 nortest_1.0-4 \n[141] jmv_1.2.5 Rcpp_1.0.3 car_3.0-7 broom_0.5.5 \n[145] metafor_2.1-0 ez_4.4-0 BayesFactor_0.9.12-4.2 metaplus_0.7-11 \n[149] later_1.0.0 httr_1.4.1 effectsize_0.2.0 sjstats_0.17.9 \n[153] colorspace_1.4-1 rvest_0.3.5 XML_3.99-0.3 fs_1.3.2 \n[157] truncnorm_1.0-8 rematch2_2.1.0 expm_0.999-4 mapproj_1.2.7 \n[161] jcolors_0.0.4 MuMIn_1.43.15 xtable_1.8-4 jsonlite_1.6.1 \n[165] nloptr_1.2.2.1 corpcor_1.6.9 rstan_2.19.3 glasso_1.11 \n[169] zeallot_0.1.0 modeltools_0.2-23 scico_1.1.0 R6_2.4.1 \n[173] Hmisc_4.3-1 broom.mixed_0.2.4 pillar_1.4.3 htmltools_0.4.0 \n[177] mime_0.9 glue_1.3.2 fastmap_1.0.1 minqa_1.2.4 \n[181] codetools_0.2-16 maps_3.3.0 pkgbuild_1.0.6 mvtnorm_1.1-0 \n[185] lattice_0.20-40 numDeriv_2016.8-1.1 huge_1.3.4 curl_4.3 \n[189] DescTools_0.99.34 gtools_3.8.1 clipr_0.7.0 magick_2.3 \n[193] logspline_2.1.15 zip_2.0.4 survival_3.1-11 rmarkdown_2.1 \n[197] qgraph_1.6.5 repr_1.1.0 munsell_0.5.0 semPlot_1.1.2 \n[201] sjmisc_2.8.3 haven_2.2.0 reshape2_1.4.3 gtable_0.3.0 \n[205] bayestestR_0.5.2 \nRun Code Online (Sandbox Code Playgroud)\n\n针对这个问题的Github问题:
\n\n\n@IndrajeetPatil 弄清楚了。
这是因为数据框包含一个名为“变量”的列。
解决此问题的最简单方法是更改数据框中“变量”的名称。这个对我有用。
https://github.com/IndrajeetPatil/groupedstats/issues/24