【问题标题】:Plotting 3D bars on top of the map using R使用 R 在地图顶部绘制 3D 条形图
【发布时间】:2017-05-26 08:54:21
【问题描述】:

我找到了一种绘制 3D 条形图的方法 (ggplot2 3D Bar Plot)。谢谢@jbaums

但是,有没有办法将底部刻面更改为地图?所以我可以清楚地可视化,例如,使用地图上的条形图来显示不同部分之间的差异的人口密度?先感谢您。 plotting 3D bars on top of the map

【问题讨论】:

标签: r 3d


【解决方案1】:

这是一种方法

# Plotting 3D maps using OpenStreetMap and RGL. For info see: 
# http://geotheory.co.uk/blog/2013/04/26/plotting-3d-maps-with-rgl/
map3d <- function(map, ...){
  if(length(map$tiles)!=1){stop("multiple tiles not implemented") }
  nx = map$tiles[[1]]$xres
  ny = map$tiles[[1]]$yres
  xmin = map$tiles[[1]]$bbox$p1[1]
  xmax = map$tiles[[1]]$bbox$p2[1]
  ymin = map$tiles[[1]]$bbox$p1[2]
  ymax = map$tiles[[1]]$bbox$p2[2]
  xc = seq(xmin,xmax,len=ny)
  yc = seq(ymin,ymax,len=nx)
  colours = matrix(map$tiles[[1]]$colorData,ny,nx)
  m = matrix(0,ny,nx)
  surface3d(xc,yc,m,col=colours, ...)
  return(list(xc=xc, yc=yc, colours=colours))
}
require(rgl)
require(OpenStreetMap)
map <- openproj(openmap(c(52.5227,13.2974),c(52.4329,13.5669), zoom = 10))
set.seed(1)
n <- 30
bbox <- unlist(map$bbox, use.names = F)
x <- do.call(runif, c(list(n), as.list(bbox[c(1,3)])))
y <- do.call(runif, c(list(n), as.list(bbox[c(4,2)])))
z <- runif(n, 0, .1)
m <- rbind(cbind(x,y,z=0), cbind(x,y,z))
m <- m[as.vector(mapply(c, 1:n, (n+1):(2*n))),]
open3d(windowRect=c(100,100,800,600))
coords <- map3d(map, lit=F)
segments3d(m, col="red", add=T)

这会给你类似的东西:

还有另一种方式,您可以将其扩展为使用 box3D 以使其看起来更像您的示例:

library(plot3D)
with(coords, {
  image3D(
    z = 0, x = xc, y = yc, colvar = colours, zlim = c(0,max(z)), 
    scale=F, theta = 0, bty="n")
  segments3D(x,y,rep(0,length(x)),x,y,z, col="red", add=T)
})

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-27
    • 1970-01-01
    • 2013-04-08
    • 2023-03-22
    • 2021-11-03
    • 1970-01-01
    相关资源
    最近更新 更多