Can xlim() and ylim() accept geometries like polygons as arguments?

18 views
Skip to first unread message

gregor...@gmail.com

unread,
Jul 18, 2014, 2:30:31 PM7/18/14
to ggp...@googlegroups.com
I'm using ggplot2 for plotting spatial data. I want my plots to look something like this:

In order to have the colored layer (mean) appear as the multi-polygon that it does, I've had to take some undesirable measures. I've taken a data frame of mean values corresponding to lat and long coordinates, which is at a 1 degree resolution, converted it to a raster, up-sized the raster by 10^5x pixels, clipped the resulting monster-raster to the boundaries of a multi-polygon in a shapefile using gdal_translate (outside of R), imported the up-sampled and clipped raster back into R, and finally plotted it. All that, simply to mask the area of interest for the plot.

It has occurred to me that xlim() and ylim() drop data outside of the constraints provided by their arguments. If those constraints could represent a multi-polygon, then I could use the original data, saving me the hassle of all that file manipulation and more importantly, speeding up the plotting by reducing the size of the data by a rather large factor. So my question is, can xlim() and ylim() accept geometries as arguments and if so, then how?


Dennis Murphy

unread,
Jul 18, 2014, 3:13:23 PM7/18/14
to gregor...@gmail.com, ggplot2
Short answer: No. The arguments to xlim must be either numeric, factor or character. See ?ggplot2::xlim.

Dennis


--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

gregor...@gmail.com

unread,
Jul 19, 2014, 1:26:42 AM7/19/14
to ggp...@googlegroups.com
Thanks. I'm thinking I may be able to create the effect I want using polygon layers for masks.

Maihemuti, Kare

unread,
Jul 19, 2014, 6:01:17 AM7/19/14
to ggp...@googlegroups.com

Hi All,

I was making a bar plot step by step and I want to change the resolution and other futures for journal publication.

I tried to following code and I got the graphic, but I do not know the plot name. I need to plot it after change the resolution.

Please help me

 

a <- c(1, 3, 9, 11, 29)

b <- c(5, 8, 11, 22, 30)

means <- c(mean(a), mean(b))

mp <- barplot(means, axes=FALSE, axisnames=FALSE, ylim=c(0, 60),

+               col=c(red, blue), main="Average age", xlab="Group", ylab="Age")

mp <- barplot(means, axes=FALSE, axisnames=FALSE, ylim=c(0, 60),

+               col=c(green, blue), main="Average age", xlab="Group", ylab="Age")

mp <- barplot(means, axes=FALSE, axisnames=FALSE, ylim=c(0, 60),

+                main="Average age", xlab="Group", ylab="Age")

axis(1, labels=c("A", "B"), at = mp)

axis(2, at=seq(0 , 60, by=5))

box()

stDevs <- matrix(c(sd(a), sd(b)), 2)

segments(mp, means - stDevs, mp, means + stDevs, lwd=2)

segments(mp - 0.1, means - stDevs, mp + 0.1, means - stDevs, lwd=2)

segments(mp - 0.1, means + stDevs, mp + 0.1, means + stDevs, lwd=2)

png(filename = "mp.png",

+     width = 4800, height = 4800, units = "px", pointsize = 12,

+     bg = "white", res = 1000, family = "", restoreConsole = TRUE,

+     type = c("windows"))

plot(mp)?----this is my question what is the final plot name.

dev.off()

RStudioGD

        2

 

 

Cheers,

Mahmut

Charles Sturt University

|   ALBURY-WODONGA   |   BATHURST   |   CANBERRA   |   DUBBO   |   GOULBURN   |   MELBOURNE   |   ONTARIO   |   ORANGE   |   PORT MACQUARIE   |   SYDNEY   |   WAGGA WAGGA   |


LEGAL NOTICE
This email (and any attachment) is confidential and is intended for the use of the addressee(s) only. If you are not the intended recipient of this email, you must not copy, distribute, take any action in reliance on it or disclose it to anyone. Any confidentiality is not waived or lost by reason of mistaken delivery. Email should be checked for viruses and defects before opening. Charles Sturt University (CSU) does not accept liability for viruses or any consequence which arise as a result of this email transmission. Email communications with CSU may be subject to automated email filtering, which could result in the delay or deletion of a legitimate email before it is read at CSU. The views expressed in this email are not necessarily those of CSU.

Charles Sturt University in Australia The Grange Chancellery, Panorama Avenue, Bathurst NSW Australia 2795 (ABN: 83 878 708 551; CRICOS Provider Number: 00005F (National)). TEQSA Provider Number: PV12018
Charles Sturt University in Ontario 860 Harrington Court, Burlington Ontario Canada L7N 3N4 Registration: www.peqab.ca

Consider the environment before printing this email.
Reply all
Reply to author
Forward
0 new messages