在“地球”上画图
主要使用threejs包来进行。
实例:绘制飞机出发地到目的地的弧线
上代码:
library(readr)
#航空飞机出发地和目的地信息,机场代码和坐标。
flights <- read_tsv('http://www.jaredlander.com/data/Flights_Jan_2.tsv')
#出发地和目的地相同的多次航班只绘制一条线
airports <- flights %>%
count(From_Lat, From_Long) %>%
arrange(desc(n))
#globejs函数需要输入球体的图片,也可以使用threejs包默认的图片
#NASA的高清“蓝色玛瑙”图片,该图片更美观。
earth <- "http://eoimages.gsfc.nasa.gov/images/imagerecords/73000/73909/world.topo.bathy.200412.3x5400x2700.jpg"
library(threejs)
globejs(img=earth, lat=airports$From_Lat, long=airports$From_Long,
value = airports$n*5, color = 'red',
arcs=flights %>%
dplyr::select(From_Lat, From_Long, To_Lat, To_Long),
arcsHeight=.4, arcsLwd=4, arcsColor="#3e4ca2", arcsOpacity=.85,
atmosphere=TRUE, fov=30, rotationlat=.5, rotationlong=-.05
)
#The first argument, img, is the image to use, which we saved to the
#earth object. The next two arguments, lat and long, are the coordinates of points to
#draw. The value argument controls how tall to draw the points. The arcs argument
#takes a four-column data.frame where the first two columns are the origin latitude and
#longitude and the second two columns are the destination latitude and longitude. The
#rest of the arguments customize the look and feel of the globe.
#要先安装需要的包,如threejs,reader,dplyr
#球形图是可以任意旋转的,也可以放大到一定倍数
threejs包的作者为Bryan Lewis。改包也可以构建三维散点图,以后就机会再学习。
赞 (0)