ggalluvial(r 包)示例给出错误
ggalluvial (r package) example gives error
我错过了什么吗? ggalluvial 包中的示例给出了这个错误:
> library(ggalluvial)
> ggplot(as.data.frame(Titanic),
+ aes(weight = Freq,
+ axis1 = Class, axis2 = Sex, axis3 = Age,
+ fill = Survived)) +
+ geom_alluvium() +
+ scale_x_continuous(breaks = 1:3, labels = c("Class", "Sex", "Age"))
Error: Invalid column specification
更新 2:
根据 DanHall 的要求:
sessionInfo()
R version 3.4.3 (2017-11-30)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
Matrix products: default
locale:
[1] LC_COLLATE=English_Canada.1252 LC_CTYPE=English_Canada.1252 LC_MONETARY=English_Canada.1252 LC_NUMERIC=C
[5] LC_TIME=English_Canada.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] ggalluvial_0.6.0 ggthemes_3.4.0 alluvial_0.1-2 dplyr_0.5.0 purrr_0.2.2 readr_0.2.2 tidyr_0.6.1
[8] tibble_1.3.4 ggplot2_2.2.1 tidyverse_1.1.1
loaded via a namespace (and not attached):
[1] Rcpp_0.12.14 compiler_3.4.3 plyr_1.8.4 base64enc_0.1-3 forcats_0.2.0 tools_3.4.3 digest_0.6.12
[8] evaluate_0.10.1 jsonlite_1.5 lubridate_1.5.6 gtable_0.2.0 nlme_3.1-128 lattice_0.20-33 rlang_0.1.4
[15] psych_1.6.4 DBI_0.6 yaml_2.1.14 parallel_3.4.3 haven_1.0.0 stringr_1.2.0 httr_1.3.1
[22] knitr_1.19 xml2_1.1.1 hms_0.3 rprojroot_1.2 grid_3.4.3 R6_2.2.2 readxl_0.1.1
[29] rmarkdown_1.8 reshape2_1.4.2 modelr_0.1.0 magrittr_1.5 backports_1.1.1 htmltools_0.3.6 scales_0.5.0
[36] rsconnect_0.8.5 assertthat_0.1 mnormt_1.5-4 rvest_0.3.2 colorspace_1.3-2 labeling_0.3 stringi_1.1.6
[43] lazyeval_0.2.1 munsell_0.4.3 broom_0.4.1
见下文,此代码可在另一台机器上运行。当对其他人有用的东西对你不起作用时,运行 update.packages()
并按照说明更新你可能已安装的任何过时的软件包会很有用。这就是这里的解决方案。
它在我的机器上按原样运行:
ggplot(as.data.frame(Titanic),
aes(weight = Freq,
axis1 = Class, axis2 = Sex, axis3 = Age,
fill = Survived)) +
geom_alluvium() +
scale_x_continuous(breaks = 1:3, labels = c("Class", "Sex", "Age"))
调用example(geom_alluvium, package = "ggalluvial")
时也有效。
这是另一个用法示例(来自小插图)。
ggplot(as.data.frame(Titanic),
aes(weight = Freq,
axis1 = Survived, axis2 = Sex, axis3 = Class)) +
geom_alluvium(aes(fill = Class),
width = 0, knot.pos = 0, reverse = FALSE) +
guides(fill = FALSE) +
geom_stratum(width = 1/8, reverse = FALSE) +
geom_text(stat = "stratum", label.strata = TRUE, reverse = FALSE) +
scale_x_continuous(breaks = 1:3, labels = c("Survived", "Sex", "Class")) +
coord_flip() +
ggtitle("Titanic survival by class and sex")
我错过了什么吗? ggalluvial 包中的示例给出了这个错误:
> library(ggalluvial)
> ggplot(as.data.frame(Titanic),
+ aes(weight = Freq,
+ axis1 = Class, axis2 = Sex, axis3 = Age,
+ fill = Survived)) +
+ geom_alluvium() +
+ scale_x_continuous(breaks = 1:3, labels = c("Class", "Sex", "Age"))
Error: Invalid column specification
更新 2: 根据 DanHall 的要求:
sessionInfo()
R version 3.4.3 (2017-11-30)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
Matrix products: default
locale:
[1] LC_COLLATE=English_Canada.1252 LC_CTYPE=English_Canada.1252 LC_MONETARY=English_Canada.1252 LC_NUMERIC=C
[5] LC_TIME=English_Canada.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] ggalluvial_0.6.0 ggthemes_3.4.0 alluvial_0.1-2 dplyr_0.5.0 purrr_0.2.2 readr_0.2.2 tidyr_0.6.1
[8] tibble_1.3.4 ggplot2_2.2.1 tidyverse_1.1.1
loaded via a namespace (and not attached):
[1] Rcpp_0.12.14 compiler_3.4.3 plyr_1.8.4 base64enc_0.1-3 forcats_0.2.0 tools_3.4.3 digest_0.6.12
[8] evaluate_0.10.1 jsonlite_1.5 lubridate_1.5.6 gtable_0.2.0 nlme_3.1-128 lattice_0.20-33 rlang_0.1.4
[15] psych_1.6.4 DBI_0.6 yaml_2.1.14 parallel_3.4.3 haven_1.0.0 stringr_1.2.0 httr_1.3.1
[22] knitr_1.19 xml2_1.1.1 hms_0.3 rprojroot_1.2 grid_3.4.3 R6_2.2.2 readxl_0.1.1
[29] rmarkdown_1.8 reshape2_1.4.2 modelr_0.1.0 magrittr_1.5 backports_1.1.1 htmltools_0.3.6 scales_0.5.0
[36] rsconnect_0.8.5 assertthat_0.1 mnormt_1.5-4 rvest_0.3.2 colorspace_1.3-2 labeling_0.3 stringi_1.1.6
[43] lazyeval_0.2.1 munsell_0.4.3 broom_0.4.1
见下文,此代码可在另一台机器上运行。当对其他人有用的东西对你不起作用时,运行 update.packages()
并按照说明更新你可能已安装的任何过时的软件包会很有用。这就是这里的解决方案。
它在我的机器上按原样运行:
ggplot(as.data.frame(Titanic),
aes(weight = Freq,
axis1 = Class, axis2 = Sex, axis3 = Age,
fill = Survived)) +
geom_alluvium() +
scale_x_continuous(breaks = 1:3, labels = c("Class", "Sex", "Age"))
调用example(geom_alluvium, package = "ggalluvial")
时也有效。
这是另一个用法示例(来自小插图)。
ggplot(as.data.frame(Titanic),
aes(weight = Freq,
axis1 = Survived, axis2 = Sex, axis3 = Class)) +
geom_alluvium(aes(fill = Class),
width = 0, knot.pos = 0, reverse = FALSE) +
guides(fill = FALSE) +
geom_stratum(width = 1/8, reverse = FALSE) +
geom_text(stat = "stratum", label.strata = TRUE, reverse = FALSE) +
scale_x_continuous(breaks = 1:3, labels = c("Survived", "Sex", "Class")) +
coord_flip() +
ggtitle("Titanic survival by class and sex")