这是一个例子:
library(plyr)
ps <- ldply(1:36, function(i)data.frame(s=0:i, n=i))
plot.new()
plot.window(c(1,36), c(0,1))
apply(ps, 1, function(x){
s<-x[1]; n<-x[2];
lines(c(n, n+1, n, n+1), c(s/n, s/(n+1), s/n, (s+1)/(n+1)), type="o")})
axis(1)
axis(2)
Run Code Online (Sandbox Code Playgroud)
ps代表所有点.每个点都有两个孩子.因此,从每个点到孩子们画线.

使用基本图形的解决方案:
x <- 1:36
boring <- function(x, n=1)n/(x+n-1)
plot(x, boring(x), type="l", usr=c(0, 36, 0, 1))
for(i in 1:36){
lines(tail(x, 36-i+1), head(boring(x, i), 36-i+1), type="o", cex=0.5)
lines(tail(x, 36-i+1), 1-head(boring(x, i), 36-i+1, type="o", cex=0.5))
}
Run Code Online (Sandbox Code Playgroud)

| 归档时间: |
|
| 查看次数: |
487 次 |
| 最近记录: |