Reputation: 75
I am new to R and I am trying to create a basic world map and I have tried a number of methods but my latest trial has given me a new error.
install.packages("mapdata")
install.packages("maps")
library(maps)
library(mapdata)
df1 <- data(world2MapEnv)
p <- ggplot(data = df1,
aes(x = long, y = lat,
group = group, fill = region))
p + geom_polygon(color = "gray90", size = 0.1) + guides(fill = FALSE)
I am getting an error under the first ggplot that says:
Error: `data` must be a data frame, or other object coercible by `fortify()`, not a character vector. Run `rlang::last_error()` to see where the error occurred.
How do I resolve this.
Thanks in advance.
Upvotes: 0
Views: 642
Reputation: 486
ggplot already has map data stored. A basic map with ggplot can be drawn with this code:
world_map <- map_data("world")
ggplot(world_map, aes(x = long, y = lat, group = group)) +
geom_polygon(fill="lightgray", colour = "black")
Upvotes: 1