r - ggplot2 无法识别特定的data.frame?
问题描述
这个问题对我来说太奇怪了。因此,我尝试使用交互式 ggplot2 包 ggiraphExtra 中的 ggRadar 创建雷达图,但由于某种原因,它无法识别我的特定 data.frame。强调“特别”,其他 data.frames 可以很好地使用这个 plot 语句,但我的特定 data.frame 不会。
这是使用 iris 数据集的示例,此示例运行良好。
library(ggiraph)
library(plyr)
library(reshape2)
library(moonBook)
library(ggiraphExtra)
library(ggplot2)
ggRadar(iris, mapping = NULL, rescale = TRUE, legend.position = "Top",
colour = "red", alpha = 0.3, size = 3, ylim = NULL,
scales = "fixed", use.label = FALSE, interactive = FALSE)
但是当我使用这个data.frame时:
> my_dataset
Case_1 Case_2 Case_3 Case_4 Case_5 Case_6 Case_7 Case_8
1 23.640 58.974 50.381 7.976 31.590 2.728 15.724 8.341
2 47.947 74.074 90.491 12.894 28.410 39.384 23.793 45.701
3 64.040 82.336 55.897 21.318 56.103 62.633 45.517 55.354
4 76.804 78.632 52.115 11.694 5.159 17.516 23.448 22.624
5 100.000 56.980 61.338 29.647 5.231 0.000 10.328 52.187
6 87.569 60.826 48.542 72.471 6.656 0.004 29.483 91.252
7 77.358 78.490 58.879 19.176 26.462 0.585 21.379 33.032
8 64.484 64.387 51.972 35.294 21.128 0.349 15.190 78.884
9 85.683 68.803 47.189 13.271 5.344 0.040 65.000 72.247
10 80.910 77.635 68.549 7.435 1.785 0.029 63.621 77.526
11 69.589 63.533 52.744 7.812 31.590 0.082 19.138 16.591
12 86.127 63.390 61.346 8.729 21.744 0.434 21.379 61.086
13 58.713 44.729 44.684 10.847 36.308 0.046 17.586 43.439
14 68.590 98.718 67.873 78.353 45.128 80.573 17.414 66.214
15 42.841 57.835 43.769 10.000 85.333 6.338 29.483 30.920
16 46.615 68.234 58.423 8.800 62.872 70.382 11.707 16.591
17 63.707 52.707 40.110 19.788 65.026 0.010 17.000 53.394
18 32.075 64.245 0.000 12.659 100.000 100.000 38.276 88.989
19 54.051 65.242 69.093 8.729 56.615 2.728 20.172 31.222
20 59.933 62.536 61.185 27.059 65.128 0.002 17.121 55.958
21 53.163 69.088 25.829 38.118 98.769 69.851 26.207 68.929
22 61.487 86.895 74.161 18.918 10.072 8.620 96.724 74.962
23 77.137 83.476 44.760 15.482 10.462 33.652 19.483 16.893
> class(my_dataset)
[1] "data.frame"
并使用相同的语句:
library(ggiraph)
library(plyr)
library(reshape2)
library(moonBook)
library(ggiraphExtra)
library(ggplot2)
ggRadar(my_dataset, mapping = NULL, rescale = TRUE, legend.position = "Top",
colour = "red", alpha = 0.3, size = 3, ylim = NULL,
scales = "fixed", use.label = FALSE, interactive = FALSE)
它返回一个错误,指出找不到对象“变量”。
Error in FUN(X[[i]], ...) : object 'variable' not found
会话信息:
R version 3.6.3 (2020-02-29)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18362)
Matrix products: default
locale:
[1] LC_COLLATE=English_Country.1252 LC_CTYPE=English_Country.1252 LC_MONETARY=English_Country.1252
[4] LC_NUMERIC=C LC_TIME=English_Country.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] scales_1.1.0 reticulate_1.15 spotifyr_2.1.1 crayon_1.3.4 tm_0.7-7
[6] NLP_0.2-0 tibble_3.0.0 magrittr_1.5 wdman_0.2.5 rvest_0.3.5
[11] xml2_1.3.1 zoo_1.8-7 rmarkdown_2.1 rio_0.5.16 shinydashboard_0.7.1
[16] rsconnect_0.8.16 shiny_1.4.0.2 ggplot2_3.3.0 ggvis_0.4.5 httr_1.4.1
[21] lubridate_1.7.8 stringr_1.4.0 data.table_1.12.8 tidyr_1.0.2 dplyr_0.8.5
[26] imputeTS_3.0 googlesheets4_0.2.0.9000 GTT_0.0.1.902 gtrendsR_1.4.4 readr_1.3.1
[31] ggiraphExtra_0.2.9 moonBook_0.2.3 reshape2_1.4.4 plyr_1.8.6 ggiraph_0.7.0
[36] RSelenium_1.7.7
loaded via a namespace (and not attached):
[1] readxl_1.3.1 uuid_0.1-4 backports_1.1.6 systemfonts_0.2.0 tidytext_0.2.4 splines_3.6.3 mycor_0.1.1
[8] SnowballC_0.7.0 usethis_1.6.0 digest_0.6.25 htmltools_0.4.0 fansi_0.4.1 memoise_1.1.0 openxlsx_4.1.4
[15] remotes_2.1.1 genius_2.2.0 xts_0.12-0 askpass_1.1 forecast_8.12 tseries_0.10-47 prettyunits_1.1.1
[22] colorspace_1.4-1 haven_2.2.0 xfun_0.13 callr_3.4.3 jsonlite_1.6.1 glue_1.4.0 gtable_0.3.0
[29] ppcor_1.1 sjmisc_2.8.4 pkgbuild_1.0.6 semver_0.2.0 quantmod_0.4.17 stinepack_1.4 Rcpp_1.0.4.6
[36] xtable_1.8-4 foreign_0.8-75 htmlwidgets_1.5.1 RColorBrewer_1.1-2 ellipsis_0.3.0 pkgconfig_2.0.3 XML_3.99-0.3
[43] farver_2.0.3 nnet_7.3-12 tidyselect_1.0.0 labeling_0.3 rlang_0.4.5 later_1.0.0 munsell_0.5.0
[50] cellranger_1.1.0 tools_3.6.3 cli_2.0.2 generics_0.0.2 sjlabelled_1.1.3 devtools_2.3.0 evaluate_0.14
[57] fastmap_1.0.1 binman_0.1.1 processx_3.4.2 knitr_1.28 fs_1.4.1 zip_2.0.4 caTools_1.18.0
[64] purrr_0.3.4 nlme_3.1-144 mime_0.9 slam_0.1-47 tokenizers_0.2.1 compiler_3.6.3 rstudioapi_0.11
[71] curl_4.3 testthat_2.3.2 stringi_1.4.6 ps_1.3.2 desc_1.2.0 forcats_0.5.0 gdtools_0.2.2
[78] lattice_0.20-38 Matrix_1.2-18 urca_1.3-0 vctrs_0.2.4 pillar_1.4.3 lifecycle_0.2.0 lmtest_0.9-37
[85] bitops_1.0-6 insight_0.8.2 httpuv_1.5.2 R6_2.4.1 promises_1.1.0 janeaustenr_0.1.5 sessioninfo_1.1.1
[92] MASS_7.3-51.5 assertthat_0.2.1 pkgload_1.0.2 openssl_1.4.1 rprojroot_1.3-2 withr_2.1.2 fracdiff_1.5-1
[99] mgcv_1.8-31 parallel_3.6.3 hms_0.5.3 quadprog_1.5-8 grid_3.6.3 timeDate_3043.102 googledrive_1.0.0
[106] TTR_0.23-6
解决方案
以下在我的计算机上运行没有问题。您能否分享sessionInfo()
并尝试新的 R 会话。
library(ggiraph)
library(plyr)
library(reshape2)
library(moonBook)
library(ggiraphExtra)
library(ggplot2)
ggRadar(iris, mapping = NULL, rescale = TRUE, legend.position = "Top",
colour = "red", alpha = 0.3, size = 3, ylim = NULL,
scales = "fixed", use.label = FALSE, interactive = FALSE)
my_dataset <- read.table(header = TRUE, sep = ",", text =
"Case_1, Case_2, Case_3, Case_4, Case_5, Case_6, Case_7, Case_8
23.640, 58.974, 50.381,7.976, 31.590,2.728, 15.724,8.341
47.947, 74.074, 90.491, 12.894, 28.410, 39.384, 23.793, 45.701
64.040, 82.336, 55.897, 21.318, 56.103, 62.633, 45.517, 55.354
76.804, 78.632, 52.115, 11.694,5.159, 17.516, 23.448, 22.624
100.000, 56.980, 61.338, 29.647,5.231,0.000, 10.328, 52.187
87.569, 60.826, 48.542, 72.471,6.656,0.004, 29.483, 91.252
77.358, 78.490, 58.879, 19.176, 26.462,0.585, 21.379, 33.032
64.484, 64.387, 51.972, 35.294, 21.128,0.349, 15.190, 78.884
85.683, 68.803, 47.189, 13.271,5.344,0.040, 65.000, 72.247
80.910, 77.635, 68.549,7.435,1.785,0.029, 63.621, 77.526
69.589, 63.533, 52.744,7.812, 31.590,0.082, 19.138, 16.591
86.127, 63.390, 61.346,8.729, 21.744,0.434, 21.379, 61.086
58.713, 44.729, 44.684, 10.847, 36.308,0.046, 17.586, 43.439
68.590, 98.718, 67.873, 78.353, 45.128, 80.573, 17.414, 66.214
42.841, 57.835, 43.769, 10.000, 85.333,6.338, 29.483, 30.920
46.615, 68.234, 58.423,8.800, 62.872, 70.382, 11.707, 16.591
63.707, 52.707, 40.110, 19.788, 65.026,0.010, 17.000, 53.394
32.075, 64.245,0.000, 12.659,100.000,100.000, 38.276, 88.989
54.051, 65.242, 69.093,8.729, 56.615,2.728, 20.172, 31.222
59.933, 62.536, 61.185, 27.059, 65.128,0.002, 17.121, 55.958
53.163, 69.088, 25.829, 38.118, 98.769, 69.851, 26.207, 68.929
61.487, 86.895, 74.161, 18.918, 10.072,8.620, 96.724, 74.962
77.137, 83.476, 44.760, 15.482, 10.462, 33.652, 19.483, 16.893")
ggRadar(my_dataset, mapping = NULL, rescale = TRUE, legend.position = "Top",
colour = "red", alpha = 0.3, size = 3, ylim = NULL,
scales = "fixed", use.label = FALSE, interactive = FALSE)
推荐阅读
- arrays - RealmSwift 上的问题:“无效的数组输入:值 (1) 多于属性 (0)。” 在尝试持久化字符串数组时
- node.js - 如何使用 mysql 数据库进行用户身份验证
- svg - 给定 SVG 路径,使用 THREE.js 创建 3D 表面
- postgresql - 如何在 azure 管道中创建 postgres 数据库?
- swift - 分页时collectionView contentOffset发生变化 - swift - 以编程方式
- r - R求解方程 - uniroot中的错误(f,x = 2.326348,lower = 0.1,upper = 1e+08)
- python - Keras 历史回调丢失与丢失的控制台输出不匹配
- java - ClassNotFoundException 运行 jar 文件但在 Intellij 中运行良好
- python - python tkinter,将框架移动到他的旧位置
- java - 使用集合进行类型擦除