Folkes, Michael
2013-Mar-12 15:04 UTC
[R] funtion equivalent of jitter to move figures on device
hello all, I'm overlaying numerous scatter plots onto a map (done in PBSmodelling). In this case I'm placing each plot by setting par(fig) to the centroid of map polygons. The location/mapping part is not so important. There are cases of small overlaps for some plots (ie figures) so I'm keen to write or find a function that moves my small scatter plots so they don't overlap. A little like jitter, but not random in behaviour, it needs to move away from the plots it's overlapping. thanks to all Michael _______________________________________________________ Michael Folkes Salmon Stock Assessment Canadian Dept. of Fisheries & Oceans Pacific Biological Station [[alternative HTML version deleted]]
Peter Ehlers
2013-Mar-12 19:26 UTC
[R] funtion equivalent of jitter to move figures on device
On 2013-03-12 08:04, Folkes, Michael wrote:> hello all, > I'm overlaying numerous scatter plots onto a map (done in PBSmodelling). In this case I'm placing each plot by setting par(fig) to the centroid of map polygons. The location/mapping part is not so important. There are cases of small overlaps for some plots (ie figures) so I'm keen to write or find a function that moves my small scatter plots so they don't overlap. A little like jitter, but not random in behaviour, it needs to move away from the plots it's overlapping. > > thanks to all > Michael > _______________________________________________________ > Michael Folkes > Salmon Stock Assessment > Canadian Dept. of Fisheries & Oceans > Pacific Biological Station >I would investigate the subplot() function in Greg Snow's TeachingDemos package, possibly in conjunction with his updateusr() function. For interactive placement of figures, it should be possible to use locator() to place each plot. Peter Ehlers
Greg Snow
2013-Mar-12 21:46 UTC
[R] funtion equivalent of jitter to move figures on device
In addition to the other suggestions that you have received you may want to look at the spread.labs function in the TeachingDemos package and the spread.labels function in the plotrix package. These only spread in 1 dimension, but may be able to do what you want. The thigmaphobe.labels function in plotrix may be of help as well. If none of these functions does what you want then looking at the code may help with some ideas. Preventing overlap in 2 dimensions automatically while keeping things close to a certain location is not a simple task. I have written functions that do well for a particular dataset, but then fail miserably on a different one. If there is only a little overlap and that can be solved by moving just one subplot then an algorithm that may work is to start with the smallest polygon and put its plot on the map and store the coordinates that it covers, then try the next smallest polygon and if it overlaps move it a little in the direction away from the center of the one it overlaps with until they don't overlap, keep going in the order smallest to largest (since larger polygons should have more flexibility in where you can move things). Another option that sometimes works (and sometimes fails with strange results) is to create a function that for a give set of "centers" will calculate the degree of overlap and the distance from the centers to the desired location and returns a weighted sum of these values. You then use that function with the optim function it can give you location for the centers of the subplots. Getting the weighting correct is difficult, weight the overlap too much and it will spread the plots out way too much, don't give it enough weight and it will still leave you with some overlap. On Tue, Mar 12, 2013 at 9:04 AM, Folkes, Michael < Michael.Folkes@dfo-mpo.gc.ca> wrote:> hello all, > I'm overlaying numerous scatter plots onto a map (done in PBSmodelling). > In this case I'm placing each plot by setting par(fig) to the centroid of > map polygons. The location/mapping part is not so important. There are > cases of small overlaps for some plots (ie figures) so I'm keen to write or > find a function that moves my small scatter plots so they don't overlap. A > little like jitter, but not random in behaviour, it needs to move away from > the plots it's overlapping. > > thanks to all > Michael > _______________________________________________________ > Michael Folkes > Salmon Stock Assessment > Canadian Dept. of Fisheries & Oceans > Pacific Biological Station > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Gregory (Greg) L. Snow Ph.D. 538280@gmail.com [[alternative HTML version deleted]]
Seemingly Similar Threads
- lattice: passing multiple lty values to the key/legend
- Floating points and floor() ?
- Hmisc binconf function value interpretation during narrow confidence intervals
- maptools::sunriset() daylight savings to stardard time change
- binomial dist: obtaining probability of success on each trial