How to create a map of Denmark with ggmap
I have installed the following two packages:
library(ggmap)
library(maps)
I have found code online to create a world map (see below). How do I zoom the plot on a country level? For example, Denmark.
ggplot()+
borders("world", colour="gray50", fill="gray50")
r ggplot2 ggmap
migrated from stackoverflow.com 14 hours ago
This question came from our site for professional and enthusiast programmers.
add a comment |
I have installed the following two packages:
library(ggmap)
library(maps)
I have found code online to create a world map (see below). How do I zoom the plot on a country level? For example, Denmark.
ggplot()+
borders("world", colour="gray50", fill="gray50")
r ggplot2 ggmap
migrated from stackoverflow.com 14 hours ago
This question came from our site for professional and enthusiast programmers.
add a comment |
I have installed the following two packages:
library(ggmap)
library(maps)
I have found code online to create a world map (see below). How do I zoom the plot on a country level? For example, Denmark.
ggplot()+
borders("world", colour="gray50", fill="gray50")
r ggplot2 ggmap
I have installed the following two packages:
library(ggmap)
library(maps)
I have found code online to create a world map (see below). How do I zoom the plot on a country level? For example, Denmark.
ggplot()+
borders("world", colour="gray50", fill="gray50")
r ggplot2 ggmap
r ggplot2 ggmap
asked yesterday
DavidDavid
614
614
migrated from stackoverflow.com 14 hours ago
This question came from our site for professional and enthusiast programmers.
migrated from stackoverflow.com 14 hours ago
This question came from our site for professional and enthusiast programmers.
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
If we look at ?borders
and, for more into, ?map
, we see that we may use the regions
argument:
ggplot() + borders(regions = "Denmark", colour = "gray50", fill = "gray50")
1
Also, a very beautiful package for maps is leaflet: i.el <- leaflet() %>% setView(lat = 50.85045, lng = 4.34878, zoom=5) %>% addTiles(group="OSM")
– JonnyCrunch
yesterday
@Julius Vainora: Thanks. Can I add layers to this plot? For example if I find a data set with "state boundries"?
– David
yesterday
2
@David, yes, layers can be added, for instance+ geom_point(data = data.frame(x = 12, y = 56), aes(x = x, y = y))
adds a point.
– Julius Vainora
yesterday
1
When using maps, you might want to addcoord_cartesian()
, so that the scale of the x and the y axes match.
– JAD
yesterday
add a comment |
Get the bounds of Denmark in lat-long and use coord_fixed
:
ggplot() + borders("world", colour="gray50", fill="gray50") + coord_fixed(xlim=c(7, 12), ylim=c(52, 58))
You can get the bounds from the map
package:
> map("world", "Denmark", plot=FALSE)$range
[1] 8.121484 15.137110 54.628857 57.736916
And you might want to expand these a bit for nicer spacing and more context.
@ when I runmap("world","Denmark",plot=FALSE)$range
I getNULL
?
– David
yesterday
Odd. Doesmap("world","Denmark")
produce a map of Denmark? What about "France" or "Belgium"? Is it using local country names ("Danmark")? Doesmap("world")
draw a map? Doesmap("world",plot=FALSE)$names
return a vector of country/region names? If those don't work, then that's very odd and you should ask a new Q or report a bug...
– Spacedman
yesterday
@ Spacedan: None of them work eitherNULL
or error. But I can create the plots in the answers...
– David
yesterday
1
Start a new clean R session, dolibrary(maps)
, then try? Maybe you've got something masking themaps::map
function. Probablypurrr::map
? Don't uselibrary(tidyverse)
.
– Spacedman
yesterday
4
@ Spacedman: I think it is okay if I use maps::map. Maybe it thought the map function from the purrr package...
– David
yesterday
|
show 1 more comment
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "79"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f310474%2fhow-to-create-a-map-of-denmark-with-ggmap%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
If we look at ?borders
and, for more into, ?map
, we see that we may use the regions
argument:
ggplot() + borders(regions = "Denmark", colour = "gray50", fill = "gray50")
1
Also, a very beautiful package for maps is leaflet: i.el <- leaflet() %>% setView(lat = 50.85045, lng = 4.34878, zoom=5) %>% addTiles(group="OSM")
– JonnyCrunch
yesterday
@Julius Vainora: Thanks. Can I add layers to this plot? For example if I find a data set with "state boundries"?
– David
yesterday
2
@David, yes, layers can be added, for instance+ geom_point(data = data.frame(x = 12, y = 56), aes(x = x, y = y))
adds a point.
– Julius Vainora
yesterday
1
When using maps, you might want to addcoord_cartesian()
, so that the scale of the x and the y axes match.
– JAD
yesterday
add a comment |
If we look at ?borders
and, for more into, ?map
, we see that we may use the regions
argument:
ggplot() + borders(regions = "Denmark", colour = "gray50", fill = "gray50")
1
Also, a very beautiful package for maps is leaflet: i.el <- leaflet() %>% setView(lat = 50.85045, lng = 4.34878, zoom=5) %>% addTiles(group="OSM")
– JonnyCrunch
yesterday
@Julius Vainora: Thanks. Can I add layers to this plot? For example if I find a data set with "state boundries"?
– David
yesterday
2
@David, yes, layers can be added, for instance+ geom_point(data = data.frame(x = 12, y = 56), aes(x = x, y = y))
adds a point.
– Julius Vainora
yesterday
1
When using maps, you might want to addcoord_cartesian()
, so that the scale of the x and the y axes match.
– JAD
yesterday
add a comment |
If we look at ?borders
and, for more into, ?map
, we see that we may use the regions
argument:
ggplot() + borders(regions = "Denmark", colour = "gray50", fill = "gray50")
If we look at ?borders
and, for more into, ?map
, we see that we may use the regions
argument:
ggplot() + borders(regions = "Denmark", colour = "gray50", fill = "gray50")
answered yesterday
Julius Vainora
1
Also, a very beautiful package for maps is leaflet: i.el <- leaflet() %>% setView(lat = 50.85045, lng = 4.34878, zoom=5) %>% addTiles(group="OSM")
– JonnyCrunch
yesterday
@Julius Vainora: Thanks. Can I add layers to this plot? For example if I find a data set with "state boundries"?
– David
yesterday
2
@David, yes, layers can be added, for instance+ geom_point(data = data.frame(x = 12, y = 56), aes(x = x, y = y))
adds a point.
– Julius Vainora
yesterday
1
When using maps, you might want to addcoord_cartesian()
, so that the scale of the x and the y axes match.
– JAD
yesterday
add a comment |
1
Also, a very beautiful package for maps is leaflet: i.el <- leaflet() %>% setView(lat = 50.85045, lng = 4.34878, zoom=5) %>% addTiles(group="OSM")
– JonnyCrunch
yesterday
@Julius Vainora: Thanks. Can I add layers to this plot? For example if I find a data set with "state boundries"?
– David
yesterday
2
@David, yes, layers can be added, for instance+ geom_point(data = data.frame(x = 12, y = 56), aes(x = x, y = y))
adds a point.
– Julius Vainora
yesterday
1
When using maps, you might want to addcoord_cartesian()
, so that the scale of the x and the y axes match.
– JAD
yesterday
1
1
Also, a very beautiful package for maps is leaflet: i.e
l <- leaflet() %>% setView(lat = 50.85045, lng = 4.34878, zoom=5) %>% addTiles(group="OSM")
– JonnyCrunch
yesterday
Also, a very beautiful package for maps is leaflet: i.e
l <- leaflet() %>% setView(lat = 50.85045, lng = 4.34878, zoom=5) %>% addTiles(group="OSM")
– JonnyCrunch
yesterday
@Julius Vainora: Thanks. Can I add layers to this plot? For example if I find a data set with "state boundries"?
– David
yesterday
@Julius Vainora: Thanks. Can I add layers to this plot? For example if I find a data set with "state boundries"?
– David
yesterday
2
2
@David, yes, layers can be added, for instance
+ geom_point(data = data.frame(x = 12, y = 56), aes(x = x, y = y))
adds a point.– Julius Vainora
yesterday
@David, yes, layers can be added, for instance
+ geom_point(data = data.frame(x = 12, y = 56), aes(x = x, y = y))
adds a point.– Julius Vainora
yesterday
1
1
When using maps, you might want to add
coord_cartesian()
, so that the scale of the x and the y axes match.– JAD
yesterday
When using maps, you might want to add
coord_cartesian()
, so that the scale of the x and the y axes match.– JAD
yesterday
add a comment |
Get the bounds of Denmark in lat-long and use coord_fixed
:
ggplot() + borders("world", colour="gray50", fill="gray50") + coord_fixed(xlim=c(7, 12), ylim=c(52, 58))
You can get the bounds from the map
package:
> map("world", "Denmark", plot=FALSE)$range
[1] 8.121484 15.137110 54.628857 57.736916
And you might want to expand these a bit for nicer spacing and more context.
@ when I runmap("world","Denmark",plot=FALSE)$range
I getNULL
?
– David
yesterday
Odd. Doesmap("world","Denmark")
produce a map of Denmark? What about "France" or "Belgium"? Is it using local country names ("Danmark")? Doesmap("world")
draw a map? Doesmap("world",plot=FALSE)$names
return a vector of country/region names? If those don't work, then that's very odd and you should ask a new Q or report a bug...
– Spacedman
yesterday
@ Spacedan: None of them work eitherNULL
or error. But I can create the plots in the answers...
– David
yesterday
1
Start a new clean R session, dolibrary(maps)
, then try? Maybe you've got something masking themaps::map
function. Probablypurrr::map
? Don't uselibrary(tidyverse)
.
– Spacedman
yesterday
4
@ Spacedman: I think it is okay if I use maps::map. Maybe it thought the map function from the purrr package...
– David
yesterday
|
show 1 more comment
Get the bounds of Denmark in lat-long and use coord_fixed
:
ggplot() + borders("world", colour="gray50", fill="gray50") + coord_fixed(xlim=c(7, 12), ylim=c(52, 58))
You can get the bounds from the map
package:
> map("world", "Denmark", plot=FALSE)$range
[1] 8.121484 15.137110 54.628857 57.736916
And you might want to expand these a bit for nicer spacing and more context.
@ when I runmap("world","Denmark",plot=FALSE)$range
I getNULL
?
– David
yesterday
Odd. Doesmap("world","Denmark")
produce a map of Denmark? What about "France" or "Belgium"? Is it using local country names ("Danmark")? Doesmap("world")
draw a map? Doesmap("world",plot=FALSE)$names
return a vector of country/region names? If those don't work, then that's very odd and you should ask a new Q or report a bug...
– Spacedman
yesterday
@ Spacedan: None of them work eitherNULL
or error. But I can create the plots in the answers...
– David
yesterday
1
Start a new clean R session, dolibrary(maps)
, then try? Maybe you've got something masking themaps::map
function. Probablypurrr::map
? Don't uselibrary(tidyverse)
.
– Spacedman
yesterday
4
@ Spacedman: I think it is okay if I use maps::map. Maybe it thought the map function from the purrr package...
– David
yesterday
|
show 1 more comment
Get the bounds of Denmark in lat-long and use coord_fixed
:
ggplot() + borders("world", colour="gray50", fill="gray50") + coord_fixed(xlim=c(7, 12), ylim=c(52, 58))
You can get the bounds from the map
package:
> map("world", "Denmark", plot=FALSE)$range
[1] 8.121484 15.137110 54.628857 57.736916
And you might want to expand these a bit for nicer spacing and more context.
Get the bounds of Denmark in lat-long and use coord_fixed
:
ggplot() + borders("world", colour="gray50", fill="gray50") + coord_fixed(xlim=c(7, 12), ylim=c(52, 58))
You can get the bounds from the map
package:
> map("world", "Denmark", plot=FALSE)$range
[1] 8.121484 15.137110 54.628857 57.736916
And you might want to expand these a bit for nicer spacing and more context.
answered yesterday
SpacedmanSpacedman
23.1k23549
23.1k23549
@ when I runmap("world","Denmark",plot=FALSE)$range
I getNULL
?
– David
yesterday
Odd. Doesmap("world","Denmark")
produce a map of Denmark? What about "France" or "Belgium"? Is it using local country names ("Danmark")? Doesmap("world")
draw a map? Doesmap("world",plot=FALSE)$names
return a vector of country/region names? If those don't work, then that's very odd and you should ask a new Q or report a bug...
– Spacedman
yesterday
@ Spacedan: None of them work eitherNULL
or error. But I can create the plots in the answers...
– David
yesterday
1
Start a new clean R session, dolibrary(maps)
, then try? Maybe you've got something masking themaps::map
function. Probablypurrr::map
? Don't uselibrary(tidyverse)
.
– Spacedman
yesterday
4
@ Spacedman: I think it is okay if I use maps::map. Maybe it thought the map function from the purrr package...
– David
yesterday
|
show 1 more comment
@ when I runmap("world","Denmark",plot=FALSE)$range
I getNULL
?
– David
yesterday
Odd. Doesmap("world","Denmark")
produce a map of Denmark? What about "France" or "Belgium"? Is it using local country names ("Danmark")? Doesmap("world")
draw a map? Doesmap("world",plot=FALSE)$names
return a vector of country/region names? If those don't work, then that's very odd and you should ask a new Q or report a bug...
– Spacedman
yesterday
@ Spacedan: None of them work eitherNULL
or error. But I can create the plots in the answers...
– David
yesterday
1
Start a new clean R session, dolibrary(maps)
, then try? Maybe you've got something masking themaps::map
function. Probablypurrr::map
? Don't uselibrary(tidyverse)
.
– Spacedman
yesterday
4
@ Spacedman: I think it is okay if I use maps::map. Maybe it thought the map function from the purrr package...
– David
yesterday
@ when I run
map("world","Denmark",plot=FALSE)$range
I get NULL
?– David
yesterday
@ when I run
map("world","Denmark",plot=FALSE)$range
I get NULL
?– David
yesterday
Odd. Does
map("world","Denmark")
produce a map of Denmark? What about "France" or "Belgium"? Is it using local country names ("Danmark")? Does map("world")
draw a map? Does map("world",plot=FALSE)$names
return a vector of country/region names? If those don't work, then that's very odd and you should ask a new Q or report a bug...– Spacedman
yesterday
Odd. Does
map("world","Denmark")
produce a map of Denmark? What about "France" or "Belgium"? Is it using local country names ("Danmark")? Does map("world")
draw a map? Does map("world",plot=FALSE)$names
return a vector of country/region names? If those don't work, then that's very odd and you should ask a new Q or report a bug...– Spacedman
yesterday
@ Spacedan: None of them work either
NULL
or error. But I can create the plots in the answers...– David
yesterday
@ Spacedan: None of them work either
NULL
or error. But I can create the plots in the answers...– David
yesterday
1
1
Start a new clean R session, do
library(maps)
, then try? Maybe you've got something masking the maps::map
function. Probably purrr::map
? Don't use library(tidyverse)
.– Spacedman
yesterday
Start a new clean R session, do
library(maps)
, then try? Maybe you've got something masking the maps::map
function. Probably purrr::map
? Don't use library(tidyverse)
.– Spacedman
yesterday
4
4
@ Spacedman: I think it is okay if I use maps::map. Maybe it thought the map function from the purrr package...
– David
yesterday
@ Spacedman: I think it is okay if I use maps::map. Maybe it thought the map function from the purrr package...
– David
yesterday
|
show 1 more comment
Thanks for contributing an answer to Geographic Information Systems Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f310474%2fhow-to-create-a-map-of-denmark-with-ggmap%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown