简体   繁体   English

使用 ggmap 映射点

[英]Mapping points using ggmap

Data is数据是

> head(latlon1.df)
       lat       lon
1 35.86417 -95.65556
2 29.72333 -98.69444
3 29.52917 -97.46417
4 40.82806 -72.86556
5 26.73500 -81.05111
6       NA        NA
ggmap(usa) +
  geom_point(data = latlon1.df, mapping = aes(x = latlon1.df$lon, y = latlon1.df$lat), color = "red",size=1)

Keeping getting不断获得

mapping: x = ~latlon1.df$lon, y = ~latlon1.df$lat 
geom_point: na.rm = FALSE
stat_identity: na.rm = FALSE

and I do not get a map or points The map was loaded with ggmap and works correctly as a map but the points do not appear on the map position_identity and I do not get a map or points The map was loaded with ggmap and works correctly as a map but the points do not appear on the map position_identity

Your example is not a reprex because you don't provide either the library from which ggmap is called [minor] nor (a sample) of the usa dataset (or a reference to where it can be obtained) [major].您的示例不是代表,因为您既没有提供ggmap被称为 [minor] 的库, ggmap没有提供usa数据集的(样本)(或获取它的参考)[major]。 Also, please use dput() or dput(head()) to post uour input data rather than head() .另外,请使用dput()dput(head())发布您的输入数据,而不是head()

Not everyone is familiar with every R package.不是每个人都熟悉每个 R package。 Please help yourself by helping us to help you.请通过帮助我们帮助您来帮助自己。

That said, I susdepct youir problem is the syntax you are using in your geom_point .也就是说,我怀疑您的问题是您在geom_point中使用的语法。 I suspect you don't need to repeat the data frame name in thecall to aes .我怀疑您不需要在对aes的调用中重复数据框名称。 Here's a reprex demonstrating the correct usage when using different data sources in different geoms.这是一个表示在不同几何图形中使用不同数据源时的正确用法的代表。

library(tidyverse)
set.seed(123)

x <- tibble(x=rnorm(10), y=rnorm(10))
y <- tibble(x=c(0, 1), y=c(0, 1))

x %>% 
  ggplot() +
  geom_point(aes(x=x, y=y)) +
  geom_line(data=y, aes(x=x, y=y), colour="red")

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM