这些新开发的R包尝起来确实鲜
写在前面
翻了翻最近一年来cran上的R包,找了一些对我们很有用的,让当然看不完,进行了简单的了解,这里送给大家,看看是否可以帮助自己做好数据呢?
ClinReport
提供输出wrd格式的表格,这个包已经登上了cran中:https://github.com/cran/ClinReport ,在github中最近一次的跟新在2019年7月份。似乎有自己的一套语法,用于输出表格,所以我没有着急学习。使用起来是有一定的门槛:
测试:
# 安装R包
# install.packages("ClinReport")
# library(devtools) ; install_github("jfrancoiscollin/ClinReport")
library(ClinReport)
library(officer)
library(flextable)
# Load data
data(datafake)
?report.quanti
# Descriptive statistics (Numerical response and 2 explicative variables):
tab1=report.quanti(data=datafake,y="y_numeric",
x1="GROUP",x2="TIMEPOINT",at.row="TIMEPOINT",subjid="SUBJID")
tab1
doc=read_docx()
doc=report.doc(tab1,title="Example of a quantitative descriptive table",doc=doc)
# 保存word格式文件
file=paste("./wordTable",".docx",sep="")
print(doc, target =file)
pak
同时指支持CRAN, 'Bioconductor' 和 'GitHub',可以解决暗转包冲突,更快编译和安装R包。但是目前R包的安装似乎没有什么问题,哦不!有一个R包最近很难安装:ggtern:
library(devtools)
install_github("nicholasehamilton/ggtern")
install.packages("ggtern")
错误信息
** using staged installation
** R
** data
** byte-compile and prepare package for lazy loading
Error in get(x, envir = ns, inherits = FALSE) :
找不到对象'coord_transform.cartesian'
错误: unable to load R code in package 'ggtern'
停止执行
ERROR: lazy loading failed for package 'ggtern'
- removing 'C:/Users/LIULAN~1/AppData/Local/Temp/RtmpUh78uX/Rinst3e8c42721ce3/ggtern'
-----------------------------------
ERROR: package installation failed
Error: Failed to install 'ggtern' from GitHub:
System command error, exit status: 1, stdout + stderr (last 10 lines):
E> ** data
E> ** byte-compile and prepare package for lazy loading
E> Error in get(x, envir = ns, inherits = FALSE) :
E> 找不到对象'coord_transform.cartesian'
E> 错误: unable to load R code in package 'ggtern'
E> 停止执行
E> ERROR: lazy loading failed for package 'ggtern'
E> * removing 'C:/Users/LIULAN~1/AppData/Local/Temp/RtmpUh78uX/Rinst3e8c42721ce3/ggtern'
E> -----------------------------------
E> ERROR: package installation failed
这个问题挂在ggtern下面已经半年过了,却还没有得到解决,地址:https://github.com/nicholasehamilton/ggtern/issues/27
这里是使用手册:https://cran.rstudio.com/web/packages/pak/pak.pdf
我尝试使用其安装ggtern包,却还是失败:
install.packages("pak")
library(pak)
pkg_install("nicholasehamilton/ggtern")
pkg_install("ggtern")> pkg_install("gtern")
cli message statuscli message status_updatecli message status_updatecli message status_updatecli message status_updatecli message status_updatecli message status_updatecli message status_updatecli message status_updatecli message status_updatecli message status_updatecli message status_updatecli message status_updatecli message status_updatecli message status_clearError: callr subprocess failed: Cannot install packages:
* Cannot install `gtern`.
- Cannot find standard package
> pkg_install("ggtern")
cli message statuscli message status_updatecli message status_updatecli message status_updatecli message status_updatecli message status_updatecli message status_updatecli message status_updatecli message status_updatecli message status_updatecli message status_updatecli message status_updatecli message status_updatecli message status_updatecli message status_updatecli message status_clearError in any && ask : invalid 'x' type in 'x && y'
>
哎!
ggasym 提供非对称矩阵的可视化
install.packages("ggasym")
You can download and install the latest development version from the GitHub repo.
devtools::install_github("jhrcook/ggasym")
library(ggasym)
tib <- tibble(g1 = c("A", "A", "A", "A", "B", "B", "B", "C", "C", "D"),
g2 = c("B", "C", "D", "E", "C", "D", "E", "D", "E", "E"),
val_1 = seq(1, 10, 1),
val_2 = rnorm(10, mean = 0, sd = 3))
tib <- asymmetrise(tib, g1, g2)
tib$val_3 <- runif(nrow(tib))
ggplot(tib, aes(x = g1, y = g2)) +
geom_asymmat(aes(fill_tl = val_1, fill_br = val_2, fill_diag = val_3)) +
scale_fill_tl_gradient(low = "lightpink", high = "tomato") +
scale_fill_br_gradient(low = "lightblue1", high = "dodgerblue") +
scale_fill_diag_gradient(low = "yellow", high = "orange3")
功能还不错,期待利用开发一下作用。这里在github查看主要功能:https://github.com/jhrcook/ggasym/blob/master/README.Rmd
graphlayouts 提供了ggraph扩展的网络layout
github地址:https://github.com/schochastics/graphlayouts
还没有测试是否好用。
# dev version
remotes::install_github("schochastics/graphlayouts")
#CRAN
install.packages("graphlayouts")
ggparty 绘制组合图形的一种尝试
github地址:https://github.com/martin-borkovec/ggparty
devtools::install_github("martin-borkovec/ggparty",
dependencies = TRUE)
install.packages("AER")
可视化的又一种选择