Reputation:
I'm plotting two sets of data using the plot
function. They intersect at a certain point. I want to indicate this point with a dotted line from the x axis to that point, and a dotted line from the y axis to that point. Is this possible with R?
Upvotes: 0
Views: 47
Reputation: 405825
Use the abline
function with h
and v
parameters for the horizontal and vertical values, and lty
= 3 for a dotted line.
plot(c(-2,3), c(-1,5), type = "n", xlab = "x", ylab = "y", asp = 1)
abline(h = 3, v = 2, lty = 3)
Upvotes: 2
Reputation: 78822
set.seed(1492)
dat1 <- data.frame(x=c(sample(1:100, 100, replace=TRUE), 3),
y=c(sample(1:200, 100, replace=TRUE), 4))
dat2 <- data.frame(x=c(sample(1:100, 100, replace=TRUE), 3),
y=c(sample(1:200, 100, replace=TRUE), 4))
dat1[dat1$x == dat2$x & dat1$y == dat2$y,]
plot(dat1, col="blue")
points(dat2, col="red", add=TRUE)
abline(h=dat1[dat1$x == dat2$x & dat1$y == dat2$y,]$y, lty=3)
Upvotes: 2