vlambda博客
学习文章列表

R语言文章发表小技巧


R语言软件包的批量引用

写论文的时候如果用了R的软件包,需要引用,一般直接使用citation()函数可以引用当前版本的R,用citation("package_name")可以引用特定的包。展示如下:

> citation()

To cite R in publications use:

R Core Team (2019). R: A language and environment for statistical computing. R Foundation for
Statistical Computing, Vienna, Austria. URL https://www.R-project.org/.

A BibTeX entry for LaTeX users is

@Manual{,
title = {R: A Language and Environment for Statistical Computing},
author = {{R Core Team}},
organization = {R Foundation for Statistical Computing},
address = {Vienna, Austria},
year = {2019},
url = {https://www.R-project.org/},
}

We have invested a lot of time and effort in creating R, please cite it when using it for data analysis.
See also ‘citation("pkgname")’ for citing R packages.

> citation("tidyverse")

To cite package ‘tidyverse’ in publications use:

Hadley Wickham (2017). tidyverse: Easily Install and Load the 'Tidyverse'. R package version 1.2.1.
https://CRAN.R-project.org/package=tidyverse

A BibTeX entry for LaTeX users is

@Manual{,
title = {tidyverse: Easily Install and Load the 'Tidyverse'},
author = {Hadley Wickham},
year = {2017},
note = {R package version 1.2.1},
url = {https://CRAN.R-project.org/package=tidyverse},
}

如果已经在环境中使用了大量的包,则可以用knitr的write_bib函数批量导出,并写出bib格式的文件:

knitr::write_bib(c(
.packages()
), file = 'packages.bib')

这里,.packages()函数可以直接把环境中使用的所有包的字符串作为向量返回。路径和文件名在file参数中进行设置。


R语言科研画图字体格式设置

下面这段代码能够把环境设置成科研专用的字体环境,如果使用ggplot可以率先运行这一段,在进行画图。

myfree<-theme_set(theme_bw())
windowsFonts(HEL=windowsFont("Helvetica CE 55 Roman"),
RMN=windowsFont("Times New Roman"),
ARL=windowsFont("Arial"))
old_theme <- theme_update(
plot.title=element_text(family="ARL", size=22, face="bold", colour="black"),
axis.title.x=element_text(family="HEL", size=18,face="bold", colour="black"),
axis.title.y=element_text(family="HEL", size=18, face="bold",angle=90, colour="black"),
axis.text.x=element_text(family="RMN", size=16, colour="black"),
axis.text.y=element_text(family="RMN", size=16, colour="black"),
axis.ticks=element_line(colour="black"),
panel.grid.major=element_blank(),
panel.grid.minor=element_blank(),
panel.background=element_blank(),
axis.line=element_line(size=1)
)

也可以根据自己的需要修改参数。如果需要原来的设置,要重启R。目前还没有探索到能够马上恢复的方法,如果有的话请各位大神教一下。

R语言科研论文配色:ggsci

写论文的时候如果觉得配色不能满足需求,就应该换调色板,最近发现了一个包很适合SCI论文的配色,叫做ggsci。

CRAN - Package ggsci cran.r-project.org

nanxstats/ggsci github.com

里面针对不同杂志的经典配色给出了很多函数,涵盖了一些炫酷的主题。下一篇文章就用它试试。在文章中用包切莫忘了引用,具体方法见HopeR:R语言软件包的批量引用。

AAAS主题样例图