简体   繁体   中英

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

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]. Also, please use dput() or dput(head()) to post uour input data rather than head() .

Not everyone is familiar with every 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 . I suspect you don't need to repeat the data frame name in thecall to 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")

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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