Reputation: 671
In the code below, how do I minimize/remove the inner padding to make the green polygon span the entire gray bounding box?
suppressMessages(library(GISTools))
suppressMessages(library(ggplot2))
data(newhaven)
blocks_df <- fortify(blocks)
ggplot(data = blocks_df) +
geom_polygon(aes(x=long, y=lat, group = group), fill = "darkolivegreen4") +
coord_equal() +
theme(axis.title = element_blank(),
axis.text = element_blank(),
axis.ticks = element_blank())
Upvotes: 0
Views: 2101
Reputation: 2105
The coord_equal()
layer can take an expand
argument -- set that to FALSE
and the plot window will fit to the plotted data's size:
...
ggplot(data = blocks_df) +
geom_polygon(aes(x=long, y=lat, group = group), fill = "darkolivegreen4") +
# set `expand=FALSE`
coord_equal(expand=FALSE) +
theme(axis.title = element_blank(),
axis.text = element_blank(),
axis.ticks = element_blank()))
And a quick follow-up: note that the expand
parameter on most other coordinate layers (e.g. scale_x_continuous()
) needs to be a vector of length two (for "multiplicative and additive expansion constants"). So you'd say e.g. scale_x_continuous(expand=c(0,0))
in that case. :p
Upvotes: 3