如data.frame为:zz, 绘图如下:
a. single protein:线性回归画法
1. ggplot(zz,aes(x=a, y=HDL))+
geom_point(alpha=1,colour="#FFA54F")+
geom_smooth(method = lm,colour="#8B658B")+
#scale_color_brewer(palette = "Set1")+
theme_bw()+
labs(x="Ferritin",y="HDL.C",title="Pearson’s correlation test of ferritin and HDL.C")+
annotate("text", x = 1000, y = 2.5, label = "r = -0.51",colour="black",size=4)
2. library(ggstatsplot)
ggscatterstats(data = alldata,
y = TRANSFUSION.UNIT,
x = NPTXR,
centrality.para = "mean", #"mean" or "median"
margins = "both",
xfill = "#D8BFD8",
yfill = "#EEDD82",
#line.size= ,
line.color="#8B6969",
point.color="#2F4F4F",
marginal.size=4,
marginal.type = "density", # "histogram", "boxplot", "density", "violin", "densigram")
title = "Relationship between TRANSFUSION.UNIT and NPTXR")
b. ggcorrplot, 全部蛋白 global correlation map 画法
ggcorrplot(cor(alldata))
2. summary(lm(y~x),method=" ") %>%.[["coefficients"]] 正规线性回归
(其实就是:a<-lm(y~x1+x2+...,data)
plot(summary(lm(y~x),method=" ")) #绘图
3. ggcor部分数据绘图: 数据类型为data.frame,纵坐标为各指标or各蛋白,行为观测值。
data <- fortify_cor(alldata[,10:11],alldata,cluster.type = "col")
ggcor<-ggcor(data,label_size=0.5) +
geom_colour()+
theme(axis.text.x = element_text(colour = "black",size = 4.7),
axis.text.y=element_text(size=5.5),
axis.ticks=element_blank())+
geom_num(aes(num=r),colour="black",size=1.5)
4. corrr包画法
datasets::mtcars %>%
correlate() %>%
focus(-cyl, -vs, mirror = TRUE) %>%
rearrange() %>%
network_plot(min_cor = .2)
我的R语言安装目录为
修改配置文件:
D:\Program Files\R\R-3.4.2\etc\Rprofile.site
原文件为:
把set a CRAN mirror 那里修改一下,其他的不变:
1、下载wget http://mirror.bjtu.edu.cn/cran/src/base/R-3/R-3.0.1.tar.gz
2、解压:
tar -zxvf
R-3.0.1.tar.gz
cd R-3.0.1
3、安装 (当然也可以跳过)
yum
install readline-devel
yum install libXt-devel
./configure
4、 配置环境并编译安装
#
如果使用rJava需要加上 --enable-R-shlib
(这个我不需要,所以加入到后面)
# 如果3没安装, 那么后面加上: --with-readline=no
--with-x=no
./configure --prefix=/usr/R-3.0.1
make $$ make install
5、配置环境变量并生效
vi
.bash_profile
export R_HOME=/usr/R-3.0.1
export PATH=.:$R_HOME/bin:$PATH
# 试环境变量生效
source .bash_profile
6、 命令行测试
[admin@JD
software]$ R
WARNING: ignoring environment value of R_HOME
R version 3.0.1 (2013-05-16) -- "Good Sport"
Copyright (C) 2013 The R Foundation for Statistical Computing
Platform: x86_64-unknown-linux-gnu (64-bit)
R是自由软件,不带任何担保。
在某些条件下你可以将其自由散布。
用'license()'或'licence()'来看散布的详细条件。
R是个合作计划,有许多人为之做出了贡献.
用'contributors()'来看合作者的详细情况
用'citation()'会告诉你如何在出版物中正确地引用R或R程序包。
用'demo()'来看一些示范程序,用'help()'来阅读在线帮助文件,或
用'help.start()'通过HTML浏览器来看帮助文件。
用'q()'退出R.
>q()
7、创建脚本测试(t.R)
cd
/opt/script/R
vim t.R
#!/path/to/Rscript
#第一行
x<-c(1,2,3)
#R语言代码
y<-c(102,299,301)
model<-lm(y~x)
summary(model)
8、测试:执行脚本
R CMD BATCH
--args /opt/script/R/t.R
more
/opt/script/R/t.Rout
#查看执行的结果
或者第二种方式
Rscript
/opt/script/R/test.R
#结果直接输出到终端