Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在“图形”的两侧绘制(几乎)相同的函数;“是”;轴在R?_R_Plot - Fatal编程技术网

如何在“图形”的两侧绘制(几乎)相同的函数;“是”;轴在R?

如何在“图形”的两侧绘制(几乎)相同的函数;“是”;轴在R?,r,plot,R,Plot,我有一个函数,它取决于距离,并根据你评估它的方向(东或西)表现不同。现在我有两个并排的绘图,但我需要将它们作为一个,其中轴的标签是共享的,x轴的标签是居中的。下面是代码当前外观的示例: x = (0:300) par(mfrow=c(2,2)) Idriss70 = function(x){ exp(5.6315-0.4104*7-(2.9832-0.2339*7)*log(x+10)+0.00047*x+0.12) } plot(Idriss70(x), log = "x", type="l

我有一个函数,它取决于距离,并根据你评估它的方向(东或西)表现不同。现在我有两个并排的绘图,但我需要将它们作为一个,其中轴的标签是共享的,x轴的标签是居中的。下面是代码当前外观的示例:

x = (0:300)
par(mfrow=c(2,2))

Idriss70 = function(x){
exp(5.6315-0.4104*7-(2.9832-0.2339*7)*log(x+10)+0.00047*x+0.12)
}
plot(Idriss70(x), log = "x", type="l",xlim = c(300,1), xlab="Distancia [km]",ylab="PGA [g]", main="Aroma y Humayani extendida, Mw 7,0", col="green",   panel.first = grid(equilogs = TRUE))

Idriss70 = function(x){
ifelse (x >= 0 & x<=3, exp(5.6315-0.4104*7-(2.9832-0.2339*7)*log(0+10)+0.00047*0+0.12),
      exp(5.6315-0.4104*7-(2.9832-0.2339*7)*log(x+10)+0.00047*x+0.12))
}
plot(Idriss70(x), log = "x", type="l", xlab="Distancia [km]",ylab="PGA [g]", main="Aroma y Humayani extendida, Mw 7,0", col="green", panel.first = grid(equilogs = TRUE))
x=(0:300)
par(mfrow=c(2,2))
Idriss70=功能(x){
exp(5.6315-0.4104*7-(2.9832-0.2339*7)*对数(x+10)+0.00047*x+0.12)
}
绘图(Idriss70(x),log=“x”,type=“l”,xlim=c(300,1),xlab=“distance[km]”,ylab=“PGA[g]”,main=“Aroma y Humayani extendida,Mw 7,0”,col=“green”,panel.first=grid(equalogs=TRUE))
Idriss70=功能(x){

如果else(x>=0&x您基本上可以绘制一个绘图,然后使用
fig
进行处理,这样您就可以将第一个绘图限制在设备的左半部分,将第二个绘图限制在设备的右半部分

x <- 0:300

Idriss70 = function(x){
  exp(5.6315-0.4104*7-(2.9832-0.2339*7)*log(x+10)+0.00047*x+0.12)
}

Idriss71 = function(x){
  ifelse(x >= 0 & x<=3,
         exp(5.6315-0.4104*7-(2.9832-0.2339*7)*log(0+10)+0.00047*0+0.12),
         exp(5.6315-0.4104*7-(2.9832-0.2339*7)*log(x+10)+0.00047*x+0.12))
}

par(fig = c(0, .5, 0, 1), mar = c(5, 4, 4, 0), xaxs = 'i', ann = FALSE)
plot(Idriss70(x), log = "x", type="l", xlim = c(300,1),
     col="green", axes = FALSE, panel.first = grid(equilogs = TRUE))
xx <- axis(1)
axis(2)

par(fig = c(.5, 1, 0, 1), new = TRUE, mar = c(5, 0, 4, 2))
plot(Idriss71(x), log = "x", type="l", col="green",
     panel.first = grid(equilogs = TRUE), axes = FALSE)
axis(1, at = xx, labels = c('', xx[-1]))

title(xlab = "Distancia [km]", main = 'Aroma y Humayani extendida, Mw 7,0',
      ylab = 'PGA [g]', outer = TRUE, line = -1.5)

@我怀疑哈德利会同意这个x轴。谢谢你的回答,这正是我想要做的,它给了我一些线索来解决我遇到的其他问题。
graphics.off()
par(mfrow = c(1, 2), mar = c(5, 4, 4, 0), xaxs = 'i', ann = FALSE)
plot(Idriss70(x), log = "x", type="l", xlim = c(300,1),
     col="green", axes = FALSE, panel.first = grid(equilogs = TRUE))
xx <- axis(1)
axis(2)

par(mar = c(5, 0, 4, 2))
plot(Idriss71(x), log = "x", type="l", col="green",
     panel.first = grid(equilogs = TRUE), axes = FALSE)
axis(1, at = xx, labels = c('', xx[-1]))

title(xlab = "Distancia [km]", main = 'Aroma y Humayani extendida, Mw 7,0',
      ylab = 'PGA [g]', outer = TRUE, line = -1.5)