Graphics Reference
In-Depth Information
# The 'state' column in the crimes data is to be matched to the 'region' column
# in the states_map data
ggplot(crimes, aes(map_id
=
state, fill
=
Assault))
+
geom_map(map
=
states_map)
+
expand_limits(x
=
states_map$long, y
=
states_map$lat)
+
coord_map(
"polyconic"
)
Notice that we also needed to use
expand_limits()
. This is because unlike most geoms,
geom_map()
doesn't automatically set the
x
and
y
limits; the use of
expand_limits()
makes it
include those
x
and
y
values. (Another way to accomplish the same result is to use
ylim()
and
xlim()
.)
See Also
For an example of data overlaid on a map, see
Creating a Vector Field
.
For more on using continuous colors, see
Using a Manually Deined Palette for a Continuous
Making a Map with a Clean Background
Problem
You want to remove background elements from a map.
Solution
First, save the following theme:
# Create a theme with many of the background elements removed
theme_clean
<-
function
function
(base_size
=
12
) {
require(grid)
# Needed for unit() function
theme_grey(base_size)
%+
replace
%
theme(
axis.title
=
element_blank(),
axis.text
=
element_blank(),
panel.background
=
element_blank(),
panel.grid
=
element_blank(),
axis.ticks.length
=
unit(
0
,
"cm"
),
axis.ticks.margin
=
unit(
0
,
"cm"
),
panel.margin
=
unit(
0
,
"lines"
),
plot.margin
=
unit(c(
0
,
0
,
0
,
0
),
"lines"
),
complete
=
TRUE
TRUE