1

I have a simple map and like to export the used coordinates of latitude/longitude into an external CSV file. Is this possible?

library('maps')
map(database='world',regions='germany')
1

The (invisible) return value of map is a list with x, y, range, and names components (See Value section in the manual page, i.e. ?map):

dat <- map(database="world",regions = "germany", plot = FALSE)
str(dat)
# List of 4
#  $ x    : num [1:596] 14.2 14.2 14 13.9 13.9 ...
#  $ y    : num [1:596] 53.9 53.9 53.9 53.9 53.9 ...
#  $ range: num [1:4] 5.86 15.02 47.28 55.06
#  $ names: chr [1:7] "Germany:Usedom" "Germany:Fehmarn" "Germany:Rugen" "Germany:4" ...
#  - attr(*, "class")= chr "map"
write.table(data.frame(x = dat$x, y = dat$y), "germany.csv")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.