我有一系列坐标用于采样数据,这是在地图上的示例:
library(ggplot2)
library(ggmap)
library(dismo)
lon <- c(-64.723946, -64.723754, -64.723808, -64.724004)
lat <- c(32.350843, 32.350783, 32.350618, 32.350675)
df <- as.data.frame(cbind(lon,lat))
mapgilbert <- get_map(location = c(lon = mean(df$lon), lat = mean(df$lat)), zoom = 18, maptype = "satellite", scale = 2)
ggmap(mapgilbert) +
geom_point(data = df, aes(x = lon, y = lat, fill = "red", alpha = 0.8), size = 5, shape = 21) +
guides(fill=FALSE, alpha=FALSE, size=FALSE) +
scale_x_continuous(limits = c(-64.725, -64.723), expand = c(0,0)) +
scale_y_continuous(limits = c(32.350, 32.351), expand = c(0,0))
这是产生的图像:
我想在地图上的南北点之间以及东,西点之间画线-做一个加号。
但是我希望这条线包括点,而不只是一条线,因此我需要计算点的坐标。线长约三十米,每米我要一个点。我觉得sp包可能允许这样的东西,但我不知道怎么做。
谢谢,
时报
重新排列您的数据框;您真正需要的是seq
。这里是Hadley风格,但是您可以根据自己的喜好手动构建:
library(dplyr)
library(tidyr)
# group rows by opposite pairs
df2 <- df %>% group_by(group = lon %in% range(lon)) %>%
# summarize lat and lon for each group into a list of a sequence from the first to the second
summarise_each(funs(list(seq(.[1], .[2], length.out = 10)))) %>%
# expand list columns with tidyr::unnest
unnest()
head(df2)
# Source: local data frame [6 x 3]
#
# group lon lat
# (lgl) (dbl) (dbl)
# 1 FALSE -64.72395 32.35084
# 2 FALSE -64.72393 32.35082
# 3 FALSE -64.72392 32.35079
# 4 FALSE -64.72390 32.35077
# 5 FALSE -64.72388 32.35074
# 6 FALSE -64.72387 32.35072
# all I changed here is data = df2
mapgilbert <- get_map(location = c(lon = mean(df$lon), lat = mean(df$lat)), zoom = 18, maptype = "satellite", scale = 2)
ggmap(mapgilbert) +
geom_point(data = df2, aes(x = lon, y = lat, fill = "red", alpha = 0.8), size = 5, shape = 21) +
guides(fill=FALSE, alpha=FALSE, size=FALSE) +
scale_x_continuous(limits = c(-64.725, -64.723), expand = c(0,0)) +
scale_y_continuous(limits = c(32.350, 32.351), expand = c(0,0))
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句