我试图在极坐标上画线ggmap
。一般方法适用于ggplot
:
library(ggmap)
library(rgdal)
library(ggplot2)
#####################################
## build data frame with triangulation data
t1 <- c(534325, 4858925, 338, 0955)
t2 <- c(534383, 4859261, 290, 1010)
t3 <- c(534386, 4859011, 301, 1015)
df <- as.data.frame(rbind(t1, t2, t3))
colnames(df) <- c("Easting", "Northing", "Azimuth", "Time")
df$Time <- as.character(df$Time)
## plot coordinates with triangulation
ggplot(df, aes(x=Easting, y=Northing, label=Time)) +
geom_point() +
geom_text(nudge_x = 50) +
geom_spoke(aes(angle = Azimuth, radius = -500)) +
theme_bw()
没有底图的三角测量:
这就是我想要的,但背景中没有底图。
但是,当我尝试这种方法时ggmap
:
## convert utms to lat long
utmcoor <- SpatialPoints(cbind(df$Easting,df$Northing),
proj4string=CRS("+proj=utm +zone=12"))
lonlatcoor <- as.data.frame(spTransform(utmcoor,CRS("+proj=longlat")))
colnames(lonlatcoor) <- c("lon", "lat")
df$lon <- lonlatcoor$lon
df$lat <- lonlatcoor$lat
## plot on base map
zoom <- 15
meanlon <- mean(df$lon)
meanlat <- mean(df$lat)
basemap <- get_googlemap(center=c(lon=meanlon, lat=meanlat), zoom=zoom,
maptype="hybrid")
ggmap(basemap) +
geom_point(aes(x=lon, y=lat), colour="red", size=2, data=df) +
geom_spoke(aes(x=lon, y=lat, angle = Azimuth), data=df, radius=-200) +
theme_void()
我得到错误
Warning message:
Removed 3 rows containing missing values (geom_segment).
代码在没有geom_spoke
线的情况下工作正常,导致底图没有三角测量:
我知道这个功能通常用于箭袋图之类的东西。不ggmap
支持geom_spoke
?有没有我不知道的更好的功能?
提前致谢。