Comments (12)
At present, reversing the order of ylim
in a call to plot.owin
only has an effect inside that plot
call and not in subsequent plot commands. I'll investigate whether it's possible to cause a side-effect that persists in subsequent plot commands, but this may depend on the plot device.
For now, your best solution is to actually flip the objects W
and X
using affine()
from spatstat.
My comments above are incorrect - reversing the order of ylim
in the call to plot.owin
causes the coordinate system to be flipped (as one can check by inspecting par("usr")
for example), and this coordinate system should be respected by subsequent plots when add=TRUE
. So this is a bug somewhere, not a missing feature.
Could you please try adding the argument useRaster=FALSE
to the image plot, i.e.
plot(density(X,adjust=0.2), add=TRUE, useRaster=FALSE)
Please try in the cases where you were getting the wrong behaviour before. This will give us a good idea whether it's a bug in the device driver.
from spatstat.
Thanks for the fast reply and analysis.
Indeed, the argument useRaster=FALSE did the trick.
plot(density(X,adjust=0.2),add=T,useRaster=F)
I tested the command on MacOSX and now it is displayed correctly.
Only the legend in the density plot is missing. But this is a result of the created axis and master plot I think.
from spatstat.
OK, thank you. So the fix is to set useRaster=FALSE
when plotting the image.
This suggests that there is a bug in R's image display code (graphics::rasterImage
) which I will chase up.
To get the legend in the image plot in your example, you can set show.all=TRUE
. See help(plot.im)
from spatstat.
This appears to be a known R bug that was thought to have been repaired but is now happening again on some devices. I will pursue it. Thanks again for drawing this to our attention.
from spatstat.
The following code provides an example demonstrating the problem, that does not use spatstat
at all.
M <- c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,
1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0,
1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0,
0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1,
1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1,
1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0,
0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1,
1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0,
0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1,
1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
M <- matrix(M, 16, 21)
tryone <- function(flip=TRUE, raz=TRUE) {
xl <- yl <- c(0,1)
if(flip) xl <- rev(xl)
plot(0,0,xlim=xl ,ylim=yl, type="n", xlab="", ylab="",
main=paste("flip =", flip, ", useRaster =", raz))
xx <- seq(0,1,length=16)
yy <- seq(0,1,length=21)
image(xx, yy, M, add=TRUE, useRaster=raz)
}
tryall <- function() {
opa <- par(mfrow=c(2,2))
tryone(FALSE, FALSE)
tryone(FALSE, TRUE)
tryone(TRUE, FALSE)
tryone(TRUE, TRUE)
par(opa)
invisible(NULL)
}
tryall()
from spatstat.
It seems unlikely that this bug in the device drivers will be fixed soon. The bug tracker says that this bug was reported in 2014. The R help files for image.default
and rasterImage
contain disclaimers about the rendering of images on some devices.
from spatstat.
Thanks for the analysis and the example. So the solution at the moment is to use the raster argument.
Apropos, the argument show.all=TRUE
only works if I plot the density in a default main plot. If I add it to an existing plot (see code above) it isn't displayed.
from spatstat.
Apropos, the argument show.all=TRUE only works if I plot the density in a default main plot. If I add it to an existing plot (see code above) it isn't displayed.
Hmm, ... that is supposed to work..... I can only imagine that perhaps the originally-declared plot area is not large enough to contain the ribbon at the intended position. Could you please try the original code but just insert W <- grow.rectangle(Frame(W), 0.2 * shortside(Frame(W)))
before the plot commands, and then see if show.all=TRUE
is working?
from spatstat.
In the current development version of spatstat
I have given plot.im
an extra argument workaround
which should also fix the problem of incorrect spatial orientation of the image. Set workaround=TRUE
to apply the workaround - but only when you know that the device driver is showing the image incorrectly.
from spatstat.
Yes you are right. if I increase the plot area it is displayed.
Here the result with 0.1:
X<- ppp(Particles$X, Particles$Y, c(0,imageSizeX), c(0,imageSizeY))
W <- Window(X)
W <- grow.rectangle(Frame(W), 0.1 * shortside(Frame(W)))
#Plot is visualized in ImageJ (Java) coordinates so we need an inverted coordinate parent plot!
plot(W, ylim=rev(W$yrange),main=NULL)
#Add a density plot and avoiding a main title here!
plot(density(X,adjust=0.2),add=T,useRaster=FALSE,show.all=TRUE,main="")
#Add the points!
plot(X, add=T)
#Add axis and title in custom font size!
axis(1,cex.axis=2)
axis(2, cex.axis=2)
title(main="Density",xlab="Width", ylab="Height", cex.lab=1.5,cex.main=3)
Great, thanks, also for the workaround.
from spatstat.
That's good!
I've also upgraded grow.rectangle
so that instead of grow.rectangle(W, 0.1 * shortside(Frame(W)))
you can now just type grow.rectangle(W, fraction=0.1)
I think we can close this issue now.
from spatstat.
Related Issues (20)
- Bug in `inradius()` for rectangular windows HOT 1
- object ‘markvario’ is not exported by 'namespace:spatstat'
- object ‘markvario’ is not exported by 'namespace:spatstat' HOT 3
- object ‘CDF’ is not exported by 'namespace:spatstat' HOT 3
- 'as.ppp' is not an exported object from 'namespace:spatstat' HOT 7
- Scaling of linim objects HOT 3
- Error when simulating determinantal point process HOT 1
- Bug in visual debugger of rmh ? HOT 3
- I cannot update spatstat HOT 1
- Pool rhohat estimates HOT 1
- object ‘as.data.frame.ppp’ is not exported by 'namespace:spatstat' HOT 5
- wrong result for the dclf statistic in dclf.test()? HOT 2
- some wrong distances in delaunayDistance() ?? HOT 2
- R code for the spatstat book HOT 2
- Install issue with spatstat.geom on R version 4.3.1 HOT 2
- rLGCP depends on RandomFieldsUtils which is no longer supported HOT 2
- Jest does not return Fest and Gest HOT 2
- Jest ignores eps HOT 6
- is.subset.owin does not recognise real subset HOT 7
- Negative values for lambda using density() HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spatstat.