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

Jesús ge@u@j| @end|ng |rom gm@||@com
Tue Mar 19 20:11:03 CET 2019


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.

El mar., 19 mar. 2019 a las 18:55, Kent Johnson (<kent3737 using gmail.com>)
escribió:

> On Tue, Mar 19, 2019 at 1:54 PM Jesús <gesusjl using gmail.com> wrote:
>
>> Hi Kent
>> Did you try using the coord_flip function from ggplot?
>> Cheers
>> Jesús
>>
>
> Yes, I did, coord_flip() doesn't work with geom_sf():
>
> > ggplot(mls) + geom_sf() + coord_flip()
> Error: geom_sf() must be used with coord_sf()
>
> Thanks for the suggestion!
> Kent
>
>>
>> El mar., 19 mar. 2019 a las 13:55, Kent Johnson (<kent3737 using gmail.com>)
>> escribió:
>>
>>> Hi,
>>>
>>> I am working with data representing cells in a tissue sample with lines
>>> and
>>> polygonal regions defined in the same space. The cells and polygons are
>>> represented and manipulated as simple features objects and visualized
>>> using
>>> ggplot2 and geom_sf. Mostly this works very well. The problem is that the
>>> coordinate system of my data has the origin at the top left corner. For
>>> data with no CRS, geom_sf puts the origin at the bottom left so all my
>>> plots are inverted.
>>>
>>> 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()
>>>
>>> Thank you for any help,
>>> Kent Johnson
>>>
>>>         [[alternative HTML version deleted]]
>>>
>>> _______________________________________________
>>> R-sig-Geo mailing list
>>> R-sig-Geo using r-project.org
>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>>
>>
>>
>> --
>> Jesús
>>
>

-- 
Jesús

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list