Coordinates don't place correctly on my map

Hi! I'm working with DMS coordinates from an excel. I want them to be placed on a Spanish map. The code is:

##Import latitude and longitude values from the excel##
datos = read_excel('excel_coordenadas.xlsx')

##Conversion from DMS coordinates to DD coordinates##

latitudes = c(datos$LATITUDES)
longitudes = c(datos$LONGITUDES)

chd_lat = substr(latitudes, 3, 3)[1] #Delete symbols such as ´,.,...
chm_lat = substr(latitudes, 6, 6)[1]
chs_lat = substr(latitudes, 12, 12)[1]

coord_lat = char2dms(latitudes,chd=chd_lat,chm=chm_lat,chs=chs_lat) #Coordinate transformation
coord_lat=as.numeric(coord_lat) #Lo transforma en un dato numerico

chd_long = substr(longitudes, 2, 2)[1]
chm_long = substr(longitudes, 5, 5)[1]
chs_long = substr(longitudes, 11, 11)[1]

coord_long = char2dms(longitudes,chd=chd_long,chm=chm_long,chs=chs_long)
coord_long = as.numeric(coord_long)

##Creating Spanish map##

mapa_mundo <- map_data("world") #Genera el mapa del mundo


coordenadas <- data.frame( long = coord_long, #Data frame with longitude and latitude data
lat= coord_lat,
stringsAsFactors = F)

mapa_mundo %>%
ggplot() +
geom_polygon(aes( x= long, y = lat, group = group),
fill = "grey80",
color = "white") +
coord_fixed (xlim= c(-12,5), #These are coordinates for Spanish peninsula
ylim= c(35,45),
ratio = 1)+
geom_point(data=coordenadas, aes(long, lat), #These are my coordinates
color= "blue", size=0.7)

The latitude seems to be well placed but the longitude does not. Can anyone help me? Thank you so much! :blush:

You don't show us your input so difficult to help you. See Minimal Reproducible Example
Does the data.frame coordenadas looks correct?
You are aware that in your substr manipulations you always extract one character?

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.