R语言基础绘图函数散点图的示例分析
今天就跟大家聊聊有关R语言基础绘图函数散点图的示例分析,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。
石林网站制作公司哪家好,找创新互联公司!从网页设计、网站建设、微信开发、APP开发、响应式网站开发等网站项目制作,到程序开发,运营维护。创新互联公司成立与2013年到现在10年的时间,我们拥有了丰富的建站经验和运维经验,来保证我们的工作的顺利进行。专注于网站建设就选创新互联公司。
被红色框线圈住的散点图

基础绘图函数箱线图
有人留言说 和原图不是很像,因为配色没有按照论文中提供的代码来。 下面是完全重复论文中的代码
cols <- c("#E69F00", "#56B4E9", "#009E73")
boxplot(log10(rel_crAss)~country,data=HMP,col=cols,
axes=F,xlab=NULL,ylab=NULL,
horizontal = T)
axis(2,at=c(1,2,3),labels=c("China", "Europe", "US"),las=1)
title("a",adj=0,line=0)

读入数据
HMP<-read.table("data/HMP.txt")
最基本的散点图
plot(rel_res~rel_crAss,data=HMP)

画图用plot()
函数,需要指定画图用到的变量y和x,还有画图用到的数据data
原始代码分别对 rel_res 和 rel_crAss取了log10
plot(log10(rel_res)~log10(rel_crAss),data=HMP)

取log10以后可以看到散点分布的更加均匀了。
按照国家分组填充颜色
cols <- c("#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00", "#CC79A7")
plot(log10(rel_res)~log10(rel_crAss), data=HMP,
bg=cols[as.factor(HMP$country)],pch=21)

更改点的大小
plot(log10(rel_res)~log10(rel_crAss), data=HMP,
bg=cols[as.factor(HMP$country)],pch=21,cex=2)

更改x轴和y轴的标签
plot(log10(rel_res)~log10(rel_crAss), data=HMP, bg=cols[as.factor(HMP$country)], pch=21,
ylab = "Normalized ARG abundance (log10)",
xlab="Normalized crAssphage abundance (log10)", cex=2)

更改坐标轴的范围
plot(log10(rel_res)~log10(rel_crAss), data=HMP,
bg=cols[as.factor(HMP$country)], pch=21,
ylab = "Normalized ARG abundance (log10)",
xlab="Normalized crAssphage abundance (log10)",
cex=2,
ylim=c(2.5, 4.5))

接下来将箱线图和散点图按照上下拼接到一起,用到的是par(fig=c(a,b,c,d))
,这里需要满足 a
具体可以参考链接 https://blog.csdn.net/qingchongxinshuru/article/details/52004182
par(fig=c(0,1,0,0.75))
plot(log10(rel_res)~log10(rel_crAss), data=HMP,
bg=cols[as.factor(HMP$country)], pch=21,
ylab = "Normalized ARG abundance (log10)",
xlab="Normalized crAssphage abundance (log10)",
cex=2,
ylim=c(2.5, 4.5))
par(fig=c(0,1,0.5,1),new=T)
boxplot(log10(rel_crAss)~country,data=HMP,col=cols,
axes=F,xlab=NULL,ylab=NULL,
horizontal = T)
axis(2,at=c(1,2,3),labels=c("China", "Europe", "US"),las=1)
title("a",adj=0,line=0)

看完上述内容,你们对R语言基础绘图函数散点图的示例分析有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注创新互联行业资讯频道,感谢大家的支持。
分享标题:R语言基础绘图函数散点图的示例分析
分享链接:http://pcwzsj.com/article/gcssdc.html