Drawing on full-region in ggplot2

When a plot of spatial data are superimposed to pictures, the size of plot need to be precisely specified.
Usually the margins outside plot area is usually useful for showing axes, labels, and legends.
However, sometimes these margins are unnecessary because it disables the precise size specification.

Here is an example of the full-region plot without margin:

p <-ggplot(data.frame(x=c(1,1,2,2),y=c(1,2,2,1)), aes(x, y)) +
  geom_polygon(fill="grey75") +
  geom_point(size=50,colour="yellow") +
    legend.position = "none",
    panel.background = theme_blank(),
    panel.grid.major = theme_blank(),
    panel.grid.minor = theme_blank(),
    panel.margin = unit(0,"null"),
    plot.margin = rep(unit(0,"null"),4),
    axis.ticks = theme_blank(),
    axis.text.x = theme_blank(),
    axis.text.y = theme_blank(),
    axis.title.x = theme_blank(),
    axis.title.y = theme_blank(),
    axis.ticks.length = unit(0,"null"),
    axis.ticks.margin = unit(0,"null")
  ) +
  scale_x_continuous(expand=c(0,0)) + scale_y_continuous(expand=c(0,0))

3 thoughts on “Drawing on full-region in ggplot2

  1. Thank you !!! I have looked all over for how to plot full-region and this is the most helpful advice I have found. Please let me know if you have any other r graphics postings.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s