帮助!我有一个森林中树木的GPS x / y位置数据集,并将这些代码放入ggplot中的漂亮地图中:
#ggmap!
library(ggmap)
library(mapproj)
map <- get_map(location = 'Madagascar', zoom = 10)
geocode("kianjavato")
#lon lat
#47.86682 -21.38024
k <- "kianjavato"
myMap <- get_map(location=k, source="stamen", maptype="toner", crop=FALSE, zoom=16)
ggmap(myMap)
m <- ggmap(myMap) + geom_point(aes(y = Lat, x = Lon, colour = Foraged, shape=Plot), data = GPS)
n <- m + scale_colour_manual(values=c("blue", "red3")) +
scale_shape_discrete(solid=F, legend=F) +
scale_y_continuous(limits=c(-21.376,-21.3715)) +
scale_x_continuous(limits=c(47.865,47.869))
plot(n)
然而,无论我尝试什么类型的代码,我都无法将箭头指向北方或缩放栏以在我的地图上绘制!我尝试了很多解决方案,其中一些看起来像这样:
尝试添加比例尺
map.scale <- ggmap(new) + (ggmap, extent = "normal", maprange = FALSE) %+% sites.data +
geom_point(aes(x = lon, y = lat, colour = colour)) +
geom_text(aes(x = lon, y = lat, label = label), hjust = 0, vjust = 0.5, size = 8/ptspermm) +
geom_segment(data = sbar, aes(x = lon.start, xend = lon.end,
y = lat.start, yend = lat.end)) +
geom_text(data = sbar, aes(x = (lon.start + lon.end)/2,
y = lat.start + 0.025*(bb$ur.lat - bb$ll.lat),
label = paste(format(distance, digits = 4, nsmall = 2),'km')),
hjust = 0.5, vjust = 0, size = 8/ptspermm) +
coord_map(projection="mercator", xlim=c(bb$ll.lon, bb$ur.lon),
ylim=c(bb$ll.lat, bb$ur.lat))
#library(SDMTools)
#Scalebar(x=47.868,y=-21.375,distance=100,unit='m') #show values in meters
#Error in map.scale(x = 50, y = -22) : argument "len" is missing, with no default
map.scale(x=47.868, y=-21.375, ratio=FALSE, relwidth=0.2)
#Error in map.scale(x = 47.868, y = -21.375, ratio = FALSE, relwidth = 0.2) :
unused argument(s) (ratio = FALSE, relwidth = 0.2)
map.scale(x=47.868, y=-21.375)
#Error in map.scale(x = 47.868, y = -21.375) :
argument "len" is missing, with no default
我需要北箭头和刻度,但都不会绘制!为什么呢?
答案 0 :(得分:4)
ggsn
包在这里很有用。如果没有GPS数据,我就无法执行您的所有脚本,但是在给定指定的x和y限制的情况下,这应该在合理的位置添加北符号和比例尺。
#First, add a scale bar.
n <- n + scalebar(location="bottomright",y.min=-21.3755, y.max=-21.3715,
x.min=47.865, x.max=47.869, dist=.1, dd2km= TRUE, model='WGS84',
st.dist=.04)
#Now add a north arrow and plot the map.
north2(n, x=.3, y=.8, symbol=9)
答案 1 :(得分:1)
尝试:
library(GISTools)
map.scale(53,15,len=12,"Miles",4,0.5,sfcol='red')
north.arrow(xb=15.75, yb=43.25, len=0.05, lab="N",col="cyan")
请查看GISTools了解更多详情。