Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/81.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_Scatter Plot - Fatal编程技术网

R 如何将这两个散点放在同一个图上进行比较?

R 如何将这两个散点放在同一个图上进行比较?,r,scatter-plot,R,Scatter Plot,现在我使用的R代码段是: a <- read.table('A.out') a <- cbind(1:nrow(a), a) colnames(a) <- c('Observation','Time') med.a <- median(a$Time) plot(a$Observation, a$Time, xaxt="n", yaxt="n", xlab="", ylab="", type="b", col="red", pch=19) abline(med.

现在我使用的R代码段是:

a <- read.table('A.out')
a <- cbind(1:nrow(a), a)
colnames(a) <- c('Observation','Time')

med.a <- median(a$Time)
plot(a$Observation, a$Time, xaxt="n", yaxt="n", xlab="",
     ylab="", type="b", col="red", pch=19)
abline(med.a,0, col='red', lty=2)
grid(col='darkgray', lty=1)

#Overlay Someone else
b <- read.table('B.out')
b <- cbind(1:nrow(b), b)
colnames(b) <- c('Observation','Time')

par(new=TRUE)
med.b <- median(b$Time)
plot(b$Observation, b$Time, xaxt="n", ylab="units", type="b", col="blue", pch=19)
abline(med.b,0, col='blue', lty=2)

您正在调用
plot
两次。每次调用都会建立一个新的坐标系。相反,使用一次调用
plot
来设置轴和坐标系,然后使用
line
来绘制实际点:

xrange <- range(c(a$Observation, b$Observation))
yrange <- range(c(a$Time, b$Time))
plot(0, type="n", xlim=xrange, ylim=yrange)
lines(a$Observation, a$Time, type="b", col="red", pch=19)
lines(b$Observation, b$Time, type="b", col="blue", pch=19)

xrange您正在调用
plot
两次。每次调用都会建立一个新的坐标系。相反,使用一次调用
plot
来设置轴和坐标系,然后使用
line
来绘制实际点:

xrange <- range(c(a$Observation, b$Observation))
yrange <- range(c(a$Time, b$Time))
plot(0, type="n", xlim=xrange, ylim=yrange)
lines(a$Observation, a$Time, type="b", col="red", pch=19)
lines(b$Observation, b$Time, type="b", col="blue", pch=19)

xrange您应该在两个绘图调用中都添加此选项:

  ..., xlim=range(c( a$Observation, b$Observation )), 
       ylim= range(c( a$Time, b$Time )),  ...

您应该在两个绘图调用中添加此选项:

  ..., xlim=range(c( a$Observation, b$Observation )), 
       ylim= range(c( a$Time, b$Time )),  ...

我们的文件
'A.out'
'B.out'
与您的文件不同,因此您的代码不可复制!您能提供一些在其他人的计算机上工作的数据吗?我们的文件
'A.out'
'B.out'
与您的不一样,因此您的代码不可复制!你能提供一些能在别人的电脑上工作的数据吗?