有人可以帮我创建一个能够执行这些情节的祝福。我知道ggplot2不支持循环。
代码:
library(ggplot2)
meanX <- 5
meanY <- 5
x <- sin(1:10)
y <- 30:21
Res <-as.data.frame(cbind(x,y))
for (i in 1:nrow(Res))
{
ggplot(Res) + geom_point(aes(x = Res$x, y = Res$y)) +
geom_segment(aes(x = meanX, y = meanY, xend = Res$x[i], yend = Res$y[i]), Res )
}
答案 0 :(得分:2)
在这种情况下,您不需要任何循环。你可以做到
ggplot(data = Res) +
geom_point(aes(x = x, y = y)) +
geom_segment(aes(x = meanX, y = meanY, xend = x, yend = y))