在r中叠加(合并)两个图像

时间:2018-12-05 01:37:04

标签: r plot leaflet

我的散点图中有如下所示的点

plot.new()  
plot.window(xlim=c(-3, 3), ylim=c(-3, 3), xaxs='i', yaxs='i')
rect(-3, -3, 0, 0, border=NA, col='#7fc97f')
rect(0, -3, 3, 0, border=NA, col='#beaed4')
rect(-3, 0, 0, 3, border=NA, col='#fdc086')
rect(0, 0, 3, 3, border=NA, col='#ffff99')  
box(lwd=0.1)
points(myData$x, myData$y, pch=15, cex=0.8)

enter image description here

和折线,这些折线使用传单包将这些点连接起来。

leaflet()%>%addPolylines(lng=myData$x, lat=myData$y)

enter image description here

我通过管理leaflet.css文件成功制作了传单的背景。但是,我仍然不知道由谁来合并这两个图像。

你能帮我吗?

1 个答案:

答案 0 :(得分:0)

   bezierCurve <- function(x, y, n=100){ 
  outx <- NULL
  outy <- NULL

  i <- 1
  for (t in seq(0, 1, length.out=n)){
    b <- bez(x, y, t)
    outx[i] <- b$x
    outy[i] <- b$y

    i <- i+1
  }
  return (list(x=outx, y=outy))
}

bez <- function(x, y, t){
  outx <- 0
  outy <- 0
  n <- length(x)-1
  for (i in 0:n){
    outx <- outx + choose(n, i)*((1-t)^(n-i))*t^i*x[i+1]
    outy <- outy + choose(n, i)*((1-t)^(n-i))*t^i*y[i+1]
  }
  return (list(x=outx, y=outy))
}

plot.new()  
plot.window(xlim=c(-3, 3), ylim=c(-3, 3), xaxs='i', yaxs='i')
rect(-5, -5, 0, 0, border=NA, col='#7fc97f')
rect(0, -5, 5, 0, border=NA, col='#beaed4')
rect(-5, 0, 0, 5, border=NA, col='#fdc086')
rect(0, 0, 5, 5, border=NA, col='#ffff99')  
box(lwd=0.1)
#points(myData$x, myData$y, "o", pch=20, cex=0.8)
points(bezierCurve(myData$x, myData$y), type="l",
       col= matlab.like(length(myData$frame)-1))