Deleting Line from Plot

graph, line, plot, r

Solution

The trick to erasing in R base is to redraw everything except what you want to erase in a new plot

so if you:

plot(x,y,main="X vs Y", xlab="X", ylab="Y")
lines(x,y,col="black",lty="dotted") 

then decide that you dont want the line then you:

plot(x,y,main="X vs Y", xlab="X", ylab="Y")

Then if you want to erase everthing then you

plot.new()

Problem

Just a quick question: I'm trying to plot a graph in R and I have covered how to do that, but how do I delete a line I have just created? For instance: ``` x <- c(1, 2, 4, 5, 6.7, 7, 8, 10 ) y <- c(40, 30, 10, 20, 53, 20, 10, 5) plot(x,y,main="X vs Y", xlab="X", ylab="Y") lines(x,y,col="black",lty="dotted") ``` This produces a nice graph. However, say I would like to delete the line I created previously (or perhaps the points as well?!) how should I go about doing it?

Original source

Related problems