开发者

for loop generates multiple plots

开发者 https://www.devze.com 2023-03-27 09:42 出处:网络
I have a question aboutthe for loop in combination with the plot function. I want to use a for loop function (see below) to plot multiple points in one plot. But my loop generates for each point his

I have a question about the for loop in combination with the plot function. I want to use a for loop function (see below) to plot multiple points in one plot. But my loop generates for each point his one plot. So with an i of 35 I generate 35 plot. My question is, is there a way to plot all the points in the same plot?

pdf("test plot.pdf")
for (i in 1开发者_Go百科:nrow(MYC)){
plot(MYC[i,1], MYC[i,2]
}
dev.off()

Thank you all!


As mentioned in the comments, you are in essence trying to do multiple plots with a loop. R doesn't understand that actually want to plot only points. There's a cure for that, and it comes in vials of points(). Before calling a loop, construct your plot using the type argument. This will make an empty plot, something along the lines of:

plot(your.data, type = "n")

You can then use your loop (with points) to add points to this existing plot.

0

精彩评论

暂无评论...
验证码 换一张
取 消