我试图在一张图上放置多个图,但每当我尝试时,这些线总是出现在新图上。我有这个:
1A<-filter(collapsed,task=="type1" & target_presence=="A")
plot(1A$set_size_num, 1A$rt, ylim=c(0,4000), xlim=c(0,30), pch=19, col="green", xlab="Set Size", ylab="Response Time (msec.)")
legend(x=0, y=4000, pch=c(19,1,19,1), col=c("green","green","red","red"), cex=0.7, legend=c("1A","1B","2A","2B"))
1Af<-lm(data=1A,rt ~ set_size_num)
summary(1Af)
abline(1Af, col="green")
1B<-filter(collapsed,task=="type1" & target_presence=="B")
plot(1B$set_size_num, 1B$rt, ylim=c(0,4000), xlim=c(0,30), pch=1, col="green", xlab="Set Size", ylab="Response Time (msec.)")
1Bf<-lm(data = 1B,rt ~ set_size_num)
summary(1Bf)
abline(1Bf,col="green")
如何在同一个地块上获得线条和点?
答案 0 :(得分:0)
在第一个实例中仅调用一次绘图,然后为后续绘图调用行。
您应该提供可重现的数据来测试您的代码,但您可以试试这个。我相信你也想根据你的传说将第二组线条的颜色编码为“红色”。
在编程注释中,对象/变量名称不应以数字开头,例如1A
,1B
,而是使用A1
,B1
...这些将在下面使用。
A1 <- filter(collapsed, task=="type1" & target_presence == "A")
A1f <- lm(data = A1, rt ~ set_size_num)
summary(A1f)
B1 <- filter(collapsed, task=="type1" & target_presence == "B")
B1f <- lm(data = B1, rt ~ set_size_num)
summary(B1f)
plot(A1$set_size_num, A1$rt, ylim=c(0,4000), xlim=c(0,30), pch=19, col="green", xlab="Set Size", ylab="Response Time (msec.)")
lines(A1$set_size_num, A1$rt, col="green")
points(B1$set_size_num, B1$rt, pch=1, col="red")
lines(B1$set_size_num, B1$rt, col="red")
abline(A1f, col="green")
abline(B1f, col="red")
legend(x=0, y=4000, pch=c(19,1,19,1), col=c("green","green","red","red"), cex=0.7, legend=c("1A","1B","2A","2B"))