绘制渐变圆

Tyl*_*ker 10 r

我试图用渐变圆重现一个Stephen Few图形,它演示了从上面出现光线的硬连线假设.这是圈子:

在此输入图像描述

我该如何重新创建呢?绘制圆圈并不算太糟糕,但添加渐变是我被抛出的地方.我认为网格可能会创造更清晰的东西,但这可能是我的错误观念.

这是绘制圆圈的开始:

## John Fox circle function
source("http://dl.dropboxusercontent.com/u/61803503/wordpress/circle_fun.txt")

par(mar=rep(1, 4), bg = "grey80")
plot.new()

for (i in seq(0, 1, by = .2)) {
    for (j in seq(.6, 1, by = .1)) {
        circle(i, j, .5, "cm", , 1)
    }
}
Run Code Online (Sandbox Code Playgroud)

相关问题:如何使用R构建具有渐变填充的气泡图

编辑:

以为我会分享结果: 在此输入图像描述

是代码.

the*_*ail 9

经过一些重复使用clip,你就可以到达那里.

# set up a blank plot
par(mar=rep(0, 4))
par(bg="#cccccc")
plot(NA,xlim=0:1,ylim=0:1)

# define a function
grad.circ <- function(centrex,centrey,radius,col,resolution) {
  colfunc <- colorRampPalette(col)
  shades <- colfunc(resolution)

  for (i in seq_along(shades) ) {
   clip(
      centrex - radius,
      centrex + radius,
      (centrey + radius) - ((i-1) * (radius*2)/length(shades)),
      (centrey + radius) - (i     * (radius*2)/length(shades))
       )
   symbols(
     centrex,
     centrey,
     circles=radius,
     bg=shades[i],
     fg=NA,
     add=TRUE,
     inches=FALSE
          )
  }
}

# call the function
grad.circ(0.5,0.5,0.5,c("black", "white"),300)
Run Code Online (Sandbox Code Playgroud)

结果:

在此输入图像描述

编辑(由Tyler Rinker撰写):

我想添加用于复制图像的其余代码:

FUN <- function(plot = TRUE, cols = c("black", "white")) {
    plot(NA, xlim=0:1, ylim=0:1, axes=FALSE)
    if (plot) {
        grad.circ(0.5, 0.5, 0.5, cols, 300)
    }
}

FUN2 <- function(){
    lapply(1:3, function(i) FUN(,c("white", "black")))
    FUN(F)
    lapply(1:3, function(i) FUN())
}


X11(10, 4.5)
par(mfrow=c(3, 7))
par(mar=rep(0, 4))
par(bg="gray70")
invisible(lapply(1:3, function(i) FUN2()))
Run Code Online (Sandbox Code Playgroud)