繁体   English   中英

如何使用固定x轴在R中的同一图形中绘制更多分布

[英]How to plot more distributions in the same graph in R with a fix x axes

我正在使用软件R创建一些分布图。 我必须查看与其他分布相比具有肥尾的分布,然后应将分布绘制在同一张图上。 问题出在x轴上,因为如果我在plot command axes = TRUE而在所有其他axes = FALSE ,则该图将不现实...仅在我将axes = TRUE分布中正确,其他将绘制在错误的轴上。 因此,您无法弄清楚谁的尾巴最胖。 我该如何解决? 实际上,应确保所有分布仅在一个x轴上绘制。

这是我的代码:

pdf("DegreeI_DDF_T.pdf")
par(mar=c(4.5,5,1,1))
plot(rankI1700~degreeI_ord1700,log="xy",main="",ylab="",xlab="",type="s",col=1,axes=TRUE,lwd=1.6)
par(new=TRUE)
plot(rankI1400~degreeI_ord1400,log="xy",main="",ylab="",xlab="",type="s",col=2,axes=FALSE,lwd=1.6)
par(new=TRUE)
plot(rankI800~degreeI_ord800,log="xy",main="",ylab="",xlab="",type="s",col=3,axes=FALSE,lwd=1.6)
par(new=TRUE)
plot(rankI50~degreeI_ord50,log="xy",main="",ylab="DDF",xlab="",type="s",lwd=1.6,col=4,axes=FALSE)

#Add legend
add_legend <- function(...) {
  opar <- par(fig=c(0, 1, 0, 1), oma=c(0, 0, 0, 0), 
    mar=c(0, 0, 0, 0), new=TRUE)
  on.exit(par(opar))
  plot(0, 0, type='n', bty='n', xaxt='n', yaxt='n')
  legend(...)
}

add_legend("bottomright", legend=c("t=500", "t=800", "t=1500","t=1585"), pch=20, 
   col=c(4,3,2,1),
   horiz=TRUE, bty='n', cex=1)

dev.off()

谢谢

此代码首先启动->

READ_DATA
 data<-read.table("df_degree_B0.00_BC0.00_l33.33_day1") df<-data.frame(time=data$V1,bank=data$V2,indegree_credit=data$V3,indegree_interbank=data$V6) rm(data) degreeI1700<-df$indegree_interbank[df$time==1700] degreeI_ord1700<-sort(degreeI1700[degreeI1700!=0],decreasing=TRUE) rankI1700<-c(1:length(degreeI_ord1700)) degreeI1400<-df$indegree_interbank[df$time==1400] degreeI_ord1400<-sort(degreeI1400[degreeI1400!=0],decreasing=TRUE) rankI1400<-c(1:length(degreeI_ord1400)) degreeI50<-df$indegree_interbank[df$time==50] degreeI_ord50<-sort(degreeI50[degreeI50!=0],decreasing=TRUE) rankI50<-c(1:length(degreeI_ord50)) degreeI800<-df$indegree_interbank[df$time==800] degreeI_ord800<-sort(degreeI800[degreeI800!=0],decreasing=TRUE) rankI800<-c(1:length(degreeI_ord800)) 

在注释中,您可以下载数据库。

这是许多可能的解决方案之一。 在数据上达到峰值,然后选择一些合理的xlimylim值。 然后使用plot(NULL, xlim = c(X_LOWER, X_UPPER), ylim = c(Y_LOWER, Y_UPPER))创建该区域的空图并使用lines函数添加每个分布。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM