Label lines in a plot

前端 未结 4 1187
伪装坚强ぢ
伪装坚强ぢ 2020-12-28 09:00

I am plotting two lines using

plot(x, y, type = \"l\", color = \"red\")

and

points(x2, y2, type = \"l\", color = \"blue\")         


        
4条回答
  •  别那么骄傲
    2020-12-28 09:42

    You can use the locator() within text() by point&click method.

    y <- rnorm(100, 10)
    y2 <- rnorm(100, 20)
    x <- 1:100
    
    plot(x, y, type = "n", ylim = c(0, 40), xlim = c(0, 120))
    lines(x, y)
    lines(x, y2, col = "red")
    text(locator(), labels = c("red line", "black line)"))
    

    alt text

提交回复
热议问题