Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/3wen/legendMap
North arrow and scale bar for ggplot2 graphics.
https://github.com/3wen/legendMap
Last synced: 3 months ago
JSON representation
North arrow and scale bar for ggplot2 graphics.
- Host: GitHub
- URL: https://github.com/3wen/legendMap
- Owner: 3wen
- Created: 2016-05-23T12:13:51.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-05-23T12:15:05.000Z (over 8 years ago)
- Last Synced: 2024-05-21T02:55:39.469Z (6 months ago)
- Language: R
- Size: 3.91 KB
- Stars: 8
- Watchers: 4
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
legendMap
==============Provides functions to add a North arrow and/or a scale bar to maps done using ggplot2.
# How to Install
```{r}
devtools::install_github("3wen/legendMap")
```# Examples
```{r}
# United States map
usa_map <- map_data("state")
P <- ggplot() + geom_polygon(data = usa_map, aes(x = long, y = lat, group = group)) + coord_map()# Let us add the scale bar (without the North arrow)
P + scale_bar(lon = -130, lat = 26,
distance_lon = 500, distance_lat = 100, distance_legend = 200,
dist_unit = "km", orientation = FALSE)# With the North arrow
P <- P + scale_bar(lon = -130, lat = 26,
distance_lon = 500, distance_lat = 100,
distance_legend = 200, dist_unit = "km")# Modifying the theme a bit
P + theme(panel.grid.minor = element_line(colour = NA), panel.grid.minor = element_line(colour = NA),
panel.background = element_rect(fill = NA, colour = NA), axis.text.x = element_blank(),
axis.text.y = element_blank(), axis.ticks.x = element_blank(),
axis.ticks.y = element_blank(), axis.title = element_blank(),
rect = element_blank(),
plot.margin = unit(0 * c(-1.5, -1.5, -1.5, -1.5), "lines"))# France map
france_map <- map_data("france")
P_fr <- ggplot() + geom_polygon(data = france_map, aes(x = long, y = lat, group = group)) + coord_map()# Let us add the scale bar
P_fr <- P_fr + scale_bar(lon = -5, lat = 42.5,
distance_lon = 100, distance_lat = 20,
distance_legend = 40, dist_unit = "km",
arrow_length = 100, arrow_distance = 60, arrow_north_size = 6)# Modifying the theme a bit
P_fr + theme(panel.grid.minor = element_line(colour = NA), panel.grid.minor = element_line(colour = NA),
panel.background = element_rect(fill = NA, colour = NA), axis.text.x = element_blank(),
axis.text.y = element_blank(), axis.ticks.x = element_blank(),
axis.ticks.y = element_blank(), axis.title = element_blank(),
rect = element_blank(),
plot.margin = unit(0 * c(-1.5, -1.5, -1.5, -1.5), "lines"))
```