0

I have data that includes the longitude and latitude of certain locations in Arizona however its over 9000 observations and ggplot2 keeps giving me "Error in st_as_sf.data.frame(data, coords = c(x, y), remove = FALSE, crs = crs) : missing values in coordinates not allowed". This data also has missing longitudes and latitudes that may be affecting the code. I need help plotting geolocations for over 9000 observations located in an excel file, excluding missing data.

I tried using ggplot2 but it kept giving me error codes and I tried mapview but I think that it may only work for smaller data observations. I still have to merge this data with 2 other 9000 observations. I think it may be because I need a bigger data visualization program but I don't know. I was expecting all the observations to be displayed on a map by themselves and then all together (layered). Any assistance would be greatly appreciated.

Irving C.
  • 3
  • 2
  • 2
    Sounds like there may be a problem with your code, or the structure of your data. It's not clear how you think we could help without seeing these. Perhaps you could edit your question to help us help you? – Allan Cameron Jan 25 '23 at 00:17
  • I am sorry I wasn't clear, yes, I need help plotting geolocations for over 9000 observations located in an excel file. This was the exact message is received from mapview "Error in st_as_sf.data.frame(data, coords = c(x, y), remove = FALSE, crs = crs) : missing values in coordinates not allowed" – Irving C. Jan 25 '23 at 00:45
  • 2
    I don't think the problem is the number of data points. Have you removed the missing values which you said you recognize exist and which seems to be what is behind the error message? – stomper Jan 25 '23 at 01:04
  • You of course cannot plot points with missing coordinates, so why not just remove them first? `yourdata <- complete.cases(yourdata)` – kjetil b halvorsen Jan 25 '23 at 01:44
  • Welcome to SO, IrvingC.! I think AllanCameron's comment could be asking you to make your question _reproducible_, as in a concrete problem with sample data and code. As it stands now, we don't know what data you are starting with, what processing you might be doing on it, nor how you are actually plotting it. The best we can do lacking that is conjecture. But SO is mostly about concrete programming problems, and this is not that. Here are some good discussions about reproducibility in Stack questions: https://stackoverflow.com/q/5963269, [mcve], and https://stackoverflow.com/tags/r/info – r2evans Jan 25 '23 at 02:07

1 Answers1

0

Would ggmap package be helpful? You may use it to download a map of Arizona and plot the data points according to their longitude and latitude on the map. For example,

AZmap = get_stamenmap(bbox=c(left = -115.63, bottom = 31.25, right =
                                 -108.84, top = 37.18),zoom = 2)
ggmap(AZmap)+ geom_point(aes(x = your longitude,
                                y = your latitude,
                                data = your data,
                                alpha = 0.1, size = 1, color = 'red')

I tried get_map or get_googlemap before but they required API key. get_stamenmap works best for me.

xyzyc
  • 16
  • 1