north arrow and scale bar in ggplot2

Showing 1-5 of 5 messages
north arrow and scale bar in ggplot2 Manuel Spínola 5/17/11 7:52 AM
Dear list members,

I am doing spatial plot with ggplot2 (data frame from a raster) and I am wonder if it is possible to include a north arrow and a scale bar in the plot.


Manuel Spínola, Ph.D.
Instituto Internacional en Conservación y Manejo de Vida Silvestre
Universidad Nacional
Apartado 1350-3000
Teléfono: (506) 2277-3598
Fax: (506) 2237-7036
Personal website: Lobito de río
Institutional website: ICOMVIS
Re: north arrow and scale bar in ggplot2 David Kahle 5/17/11 8:11 AM
Not build in. :) You could add one pretty easily with annotate() though...


You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example:
To post: email
To unsubscribe: email
More options:

Re: north arrow and scale bar in ggplot2 Manuel Spínola 5/17/11 8:21 AM
Thank you David.

How I do that?



2011/5/17 David Kahle <>
Re: north arrow and scale bar in ggplot2 Osmo Salomaa 5/19/11 12:39 AM
For anyone interested, here are two functions I wrote a while back to
simplify adding a very simple scalebar to a plot.

hscale_segment = function(breaks, ...)
    y = unique(breaks$y)
    stopifnot(length(y) == 1)
    dx = max(breaks$x) - min(breaks$x)
    dy = 1/30 * dx
    hscale = data.frame(ix=min(breaks$x), iy=y, jx=max(breaks$x),
    vticks = data.frame(ix=breaks$x, iy=(y - dy), jx=breaks$x, jy=(y +
    df = rbind(hscale, vticks)
                        aes(x=ix, xend=jx, y=iy, yend=jy),


hscale_text = function(breaks, ...)
    dx = max(breaks$x) - min(breaks$x)
    dy = 2/30 * dx
    breaks$y = breaks$y + dy
                     aes(x=x, y=y, label=label),


Then it's a simple matter of defining the break points for the
scalebar and adding layers with the two above functions to your plot.
Defining the breaks obviously depends on your coordinate system, the
below example is for a projected metric coordinate system. (ymin,
xmax) is the lower right hand corner in which the scalebar is being

scalebreaks = data.frame(x=seq(xmax - 11000, xmax - 1000, 5000),
                         y=(ymin + 1000),
                         label=c("0", "5", "10 km"))

plot = (ggplot(...)
        + ...
        + hscale_segment(scalebreaks, size=0.1)
        + hscale_text(scalebreaks, size=2)
        + ...

It will look about like this:

    0        5      10 km

Adding a north arrow should be trivial, assuming you yourself know
which way north is.
Re: north arrow and scale bar in ggplot2 Pet Chiang 11/14/14 8:24 PM
How can I find out my map xmax and ymin?