[R-sig-Geo] Reverse y-axis with geom_sf

Kent Johnson kent3737 @end|ng |rom gm@||@com
Wed Mar 20 16:50:56 CET 2019


>
> Date: Tue, 19 Mar 2019 15:13:37 +0100
> From: Edzer Pebesma <edzer.pebesma using uni-muenster.de>
> To: r-sig-geo using r-project.org
> Subject: Re: [R-sig-Geo] Reverse y-axis with geom_sf
> Message-ID: <7f743557-7a41-d93a-cbc6-5b778f862cac using uni-muenster.de>
> Content-Type: text/plain; charset="utf-8"
>
>
> On 3/19/19 2:55 PM, Kent Johnson wrote:
>
> > Is there a way to invert the y axis while staying within sf (or possibly
> > sp?) The only answers I have found involve extracting the coordinates
> from
> > the sf objects and inverting or plotting from the raw data. Maybe by
> > creating a CRS with the correct orientation?
> >
> > For a very simple example with just a few vectors - the code below plots
> an
> > arrow pointing down; I would like to invert the y-axis so it points up.
> > library(sf)
> > library(ggplot2)
> > s1 <- rbind(c(9, 11), c(10, 10))
> > s2 <- rbind(c(11, 11), c(10, 10))
> > s3 <- rbind(c(10,14), c(10, 12), c(10,10))
> > mls <- st_multilinestring(list(s1,s2,s3))
> >
> > ggplot(mls) + geom_sf()
>
> You mean, like
>
> ggplot(mls * c(1, -1)) + geom_sf()
>
> ?
>

Yes, that might work well, with the addition of a correction to the axis
labels:
ggplot(mls * c(1, -1)) + geom_sf() +
  scale_y_continuous(labels=function(x) -x)

I have a raster background that will need some adjustment too, that should
be manageable.
Thanks!
Kent

Date: Tue, 19 Mar 2019 19:11:03 +0000
> From: =?UTF-8?B?SmVzw7pz?= <gesusjl using gmail.com>
> To: Kent Johnson <kent3737 using gmail.com>
> Cc: r-sig-geo using r-project.org
> Subject: Re: [R-sig-Geo] Reverse y-axis with geom_sf
> Message-ID:
>         <
> CAGt6bQ50AcnY_FXaqeQPT3cyfL4OehGP_5UF1UyugNi-swh5Fg using mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> You are welcome
>
> You could try converting sf to sp and  use the corresponding geoms
> (geom_polygon, geom_point..etc.)  plus coord_flip() or map the x and y
> aesthetics accordingly.
>

That, or just pulling the raw data out and plotting it directly, is kind of
a last resort. I would rather not have to do this level of data munging as
my actual data is moderately complex.

Thanks,
Kent

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list