【问题标题】:R cran ggplot print mapR cran ggplot 打印地图
【发布时间】:2015-12-22 14:28:03
【问题描述】:

我正在尝试使用以下功能打印 R 地图(见底部) 输入是一个数据框,其中包含十进制格式的经度、纬度以及将被描述为彩色项目符号的错误。

这工作得很好,但我想添加一个新的额外点,除了数据框包含的内容外,它会有不同的类型(而不是点,可能是十字或正方形)并具有固定的红色,而不是按照我对其余点的颜色渐变。

你能帮我解决这个问题吗? 看待 亚历克斯

dfE<-data.frame(c(-0.1456250,-0.1442639),c(51.51476,51.51492),c(0.018878676,0.111847050))
names(dfE) <- c("Longitude", "Latitude", "Error")
stationaryPoint<-data.frame(0.1422361,51.51516)
names(stationaryPoint) <- c("Longitude", "Latitude")
data<-dfE
jet.colors <- colorRampPalette(c("#00007F", "red", "#007FFF", "yellow", "#7FFF7F", "cyan", "#FF7F00", "blue", "#7F0000"))
bbox <- c(min(data[, 1])-0.001, min(data[, 2])-0.001, max(data[, 1])+0.001, max(data[, 2])+0.001)
mp <- get_stamenmap(bbox, maptype = "toner", zoom = zoom)

ggmap(mp, darken = 0) + geom_point(aes(Longitude, Latitude, colour =Error), data = dfE, size = 3) 

我之前尝试添加以下行以将具有不同颜色和形状的额外点添加到 ggmap 行,但我总是收到错误

  • geom_point(aes(Longitude, Latitude), data =stationaryPoint, size = 3,shape=4,color="red")

【问题讨论】:

  • 请通过dput(data)提供您的数据。
  • 感谢将它们添加到我的初始帖子中
  • 我仍然无法重现您的图表。请做一个真正的reproducible example,即一个例子,我只是复制代码,它可以工作到你需要帮助的地步。
  • 谢谢。在上面添加了代码。您可能只需要加载 ggmap 库

标签: r maps


【解决方案1】:

由于您没有提供任何数据,因此很难为您提供帮助。

您的问题的解决方案可能是使用geom_point 添加另一层:

# create new data.frame with location of point you want to plot
newdata <- data.frame(Longitude = c(40.7143528), Latitude = c(-74.0059731)) # New York

ggmap(mp, darken = 0) +
  geom_point(aes(Longitude, Latitude, colour =Error), data = dfE, size = 3) +
  geom_point(data = newdata, shape = 15) +
  RestofyourCode

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-12-30
    • 2015-10-05
    • 1970-01-01
    • 2015-07-10
    • 1970-01-01
    • 1970-01-01
    • 2017-03-15
    相关资源
    最近更新 更多