Skip to content

Commit 9108d9b

Browse files
sowlathomasp85
authored andcommitted
Edit documentation to show all examples within if (require("maps")) statements (#3082)
1 parent 86fed3f commit 9108d9b

File tree

9 files changed

+121
-3
lines changed

9 files changed

+121
-3
lines changed

R/annotation-map.r

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ NULL
1717
#' ggplot(seal.sub, aes(x = long, y = lat)) +
1818
#' annotation_map(usamap, fill = "NA", colour = "grey50") +
1919
#' geom_segment(aes(xend = long + delta_long, yend = lat + delta_lat))
20+
#' }
2021
#'
22+
#' if (require("maps")) {
2123
#' seal2 <- transform(seal.sub,
2224
#' latr = cut(lat, 2),
2325
#' longr = cut(long, 2))

R/coord-map.r

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,36 +43,78 @@
4343
#'
4444
#' # Plot it in cartesian coordinates
4545
#' nzmap
46+
#' }
47+
#'
48+
#' if (require("maps")) {
4649
#' # With correct mercator projection
4750
#' nzmap + coord_map()
51+
#' }
52+
#'
53+
#' if (require("maps")) {
4854
#' # With the aspect ratio approximation
4955
#' nzmap + coord_quickmap()
56+
#' }
5057
#'
58+
#' if (require("maps")) {
5159
#' # Other projections
5260
#' nzmap + coord_map("cylindrical")
61+
#' }
62+
#'
63+
#' if (require("maps")) {
5364
#' nzmap + coord_map("azequalarea", orientation = c(-36.92, 174.6, 0))
65+
#' }
66+
#'
67+
#' if (require("maps")) {
5468
#' nzmap + coord_map("lambert", parameters = c(-37, -44))
69+
#' }
5570
#'
71+
#' if (require("maps")) {
5672
#' states <- map_data("state")
5773
#' usamap <- ggplot(states, aes(long, lat, group = group)) +
5874
#' geom_polygon(fill = "white", colour = "black")
5975
#'
6076
#' # Use cartesian coordinates
6177
#' usamap
78+
#' }
79+
#'
80+
#' if (require("maps")) {
6281
#' # With mercator projection
6382
#' usamap + coord_map()
83+
#' }
84+
#'
85+
#' if (require("maps")) {
6486
#' usamap + coord_quickmap()
87+
#' }
88+
#'
89+
#' if (require("maps")) {
6590
#' # See ?mapproject for coordinate systems and their parameters
6691
#' usamap + coord_map("gilbert")
92+
#' }
93+
#'
94+
#' if (require("maps")) {
6795
#' usamap + coord_map("lagrange")
96+
#' }
6897
#'
98+
#' if (require("maps")) {
6999
#' # For most projections, you'll need to set the orientation yourself
70100
#' # as the automatic selection done by mapproject is not available to
71101
#' # ggplot
72102
#' usamap + coord_map("orthographic")
103+
#' }
104+
#'
105+
#' if (require("maps")) {
73106
#' usamap + coord_map("stereographic")
107+
#' }
108+
#'
109+
#' if (require("maps")) {
74110
#' usamap + coord_map("conic", lat0 = 30)
111+
#' }
112+
#'
113+
#' if (require("maps")) {
75114
#' usamap + coord_map("bonne", lat0 = 50)
115+
#' }
116+
#'
117+
#' if (require("maps")) {
76118
#'
77119
#' # World map, using geom_path instead of geom_polygon
78120
#' world <- map_data("world")
@@ -83,8 +125,14 @@
83125
#'
84126
#' # Orthographic projection with default orientation (looking down at North pole)
85127
#' worldmap + coord_map("ortho")
128+
#' }
129+
#'
130+
#' if (require("maps")) {
86131
#' # Looking up up at South Pole
87132
#' worldmap + coord_map("ortho", orientation = c(-90, 0, 0))
133+
#' }
134+
#'
135+
#' if (require("maps")) {
88136
#' # Centered on New York (currently has issues with closing polygons)
89137
#' worldmap + coord_map("ortho", orientation = c(41, -74, 0))
90138
#' }

R/fortify-map.r

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
#' head(fortify(ca))
1616
#' ggplot(ca, aes(long, lat)) +
1717
#' geom_polygon(aes(group = group))
18+
#' }
1819
#'
20+
#' if (require("maps")) {
1921
#' tx <- map("county", "texas", plot = FALSE, fill = TRUE)
2022
#' head(fortify(tx))
2123
#' ggplot(tx, aes(long, lat)) +
@@ -65,7 +67,9 @@ fortify.map <- function(model, data, ...) {
6567
#' ggplot(choro, aes(long, lat)) +
6668
#' geom_polygon(aes(group = group, fill = assault)) +
6769
#' coord_map("albers", at0 = 45.5, lat1 = 29.5)
70+
#' }
6871
#'
72+
#' if (require("maps")) {
6973
#' ggplot(choro, aes(long, lat)) +
7074
#' geom_polygon(aes(group = group, fill = assault / murder)) +
7175
#' coord_map("albers", at0 = 45.5, lat1 = 29.5)
@@ -97,20 +101,25 @@ map_data <- function(map, region = ".", exact = FALSE, ...) {
97101
#' ia <- map_data("county", "iowa")
98102
#' mid_range <- function(x) mean(range(x))
99103
#' seats <- do.call(rbind, lapply(split(ia, ia$subregion), function(d) {
100-
#' data.frame(lat = mid_range(d$lat), long = mid_range(d$long))
104+
#' data.frame(lat = mid_range(d$lat), long = mid_range(d$long), subregion = unique(d$subregion))
101105
#' }))
106+
#'
102107
#' ggplot(ia, aes(long, lat)) +
103108
#' geom_polygon(aes(group = group), fill = NA, colour = "grey60") +
104109
#' geom_text(aes(label = subregion), data = seats, size = 2, angle = 45)
110+
#' }
105111
#'
112+
#' if (require("maps")) {
106113
#' data(us.cities)
107114
#' capitals <- subset(us.cities, capital == 2)
108115
#' ggplot(capitals, aes(long, lat)) +
109116
#' borders("state") +
110117
#' geom_point(aes(size = pop)) +
111118
#' scale_size_area() +
112119
#' coord_quickmap()
120+
#' }
113121
#'
122+
#' if (require("maps")) {
114123
#' # Same map, with some world context
115124
#' ggplot(capitals, aes(long, lat)) +
116125
#' borders("world", xlim = c(-130, -60), ylim = c(20, 50)) +

man/annotation_map.Rd

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/borders.Rd

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/coord_map.Rd

Lines changed: 48 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/figures/README-example-1.png

52.6 KB
Loading

man/fortify.map.Rd

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/map_data.Rd

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)