Creating maps using latitude and longitude

Load occurrence data

read.csv("C:/Users/Hp/Desktop/Demo data_LatLong.csv")
Occurrence_data<- read.csv("C:/Users/Hp/Desktop/Demo data_LatLong.csv", header=TRUE, sep=",")
View(Occurrence_data)
library(maps)
library(mapdata)
library(mapproj)

Plot occurrence points on a map

ggplot() +
borders("world", colour = "gray50", fill = "white") + # Add world borders
geom_point(mapdata = Occurrence_data, aes(x = longitude, y = latitude), color = "blue", alpha = 0.5) + # Add occurrence points
ggtitle("Distribution map of plant species")
install.packages("tidyverse")

I am trying to create an occurrence map of a plant species using the latitude and longitude data collected from the field. However, I am getting stuck at running the codes in 'R'. can anybody please help me in troubleshooting this?

Here is the error message I found
Error in FUN(X[[i]], ...) : object 'longitude' not found

This data frame must have variables named longitude and latitude. Check with

colnames(Occurrence_data)

Yes, the response comes as "Longitude" "Latitude". But, this is followed by the same error message. Here is how it looks..

1] "Longitude" "Latitude"
Error in FUN(X[[i]], ...) : object 'longitude' not found

Capitalization signifies. “Longitude” is not the same as “longitude.”

This is what the code looks like

Load occurrence data

read.csv("C:/Users/Hp/Desktop/Demo data_LatLong.csv")
Occurrence_data<- read.csv("C:/Users/Hp/Desktop/Demo data_LatLong.csv", header=TRUE, sep=",")
View(Occurrence_data)

And this is how the console has responded

Load occurrence data

read.csv("C:/Users/Hp/Desktop/Demo data_LatLong.csv")
Latitude Longitude
1 12.97912 77.59130
2 18.93877 72.83534
3 13.08017 80.28383
4 28.65172 77.22194
Occurrence_data<- read.csv("C:/Users/Hp/Desktop/Demo data_LatLong.csv", header=TRUE, sep=",")
View(Occurrence_data)
Error in FUN(X[[i]], ...) : object 'longitude' not found

My excel dataset contains two columns such as Latitude and Longitude. I am still not able to figure out where am I getting wrong.

As Technocrat said, R is case sensitive, if the variables in your data frame are capitalized you have to type them the same way in your ggplot code. The previous line should be:

geom_point(mapdata = Occurrence_data, aes(x = Longitude, y = Latitude), color = "blue", alpha = 0.5) +

Thanks @andresrcs . It worked

This map shows the entire world view. However, if I want to project only on one particular region of the world, for instance, some states of India, then how to add that one?

If you need more specific help, please provide a proper REPRoducible EXample (reprex) illustrating your issue.

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.