简体   繁体   English

有没有办法在“spatstat”包中使圆盘图的多边形边界不可见?

[英]Is there a way to render invisible the polygonal boundary of a disc plot in the 'spatstat' package?

Here is the plot.这是情节。 I want to get rid of the black line of the aperture.我想去掉光圈的黑线。

I believe the pictures are pretty self explanatory for understanding what i would like to do.我相信这些图片对于理解我想做的事情非常不言自明。 But i really have no idea how to go about this.但我真的不知道该怎么做。 Any help would be greatly appreciated.任何帮助将不胜感激。

黑色边界

But, i want it to look like the following:但是,我希望它看起来像下面这样:

在此处输入图片说明

Here is my code:这是我的代码:

library(spatstat.data)
library(nlme)
library(rpart)
library(spatstat)

repelled_points <- function(n, r_circle, r_clash) {
        container_x <- numeric(n)
        container_y <- numeric(n)
        j <- i <- 1
        while(i <= n)
        {
                j <- j + 1
                if(j == 100 * n) stop("Cannot accommodate the points in given space")
                x <- runif(1, -1, 1)
                y <- runif(1, -1, 1)
                if(x^2 + y^2 > 1) next
                if(i > 1) {
                        dist <- sqrt((x - container_x[seq(i-1)])^2 + (y - container_y[seq(i-1)])^2)
                        if(any(dist < r_clash)) next
                }
                container_x[i] <- x
                container_y[i] <- y
                i <- i + 1
                j <- 1
        }
        `class<-`(list(window = disc(centre = c(0, 0), radius = r_circle),
                       n = n, x = container_x * r_circle,
                       y = container_y * r_circle, markformat = "none"), "ppp")
}
dots <- repelled_points(18, 1, 0.35)
plot(dots, type="n")
points(dots$x[1:4], dots$y[1:4], pch=15, col="chartreuse3", cex=6)
points(dots$x[5:8], dots$y[5:8], pch=15, col="chartreuse3", cex=6)
points(dots$x[9:13], dots$y[9:13], pch=17, col="chartreuse", cex=6)
points(dots$x[14:18], dots$y[14:18], pch=17, col="chartreuse", cex=6)

Thank you!谢谢!

You can plot with lty = 0您可以使用lty = 0绘图

plot(dots, type="n", lty = 0)
points(dots$x[1:4], dots$y[1:4], pch=15, col="chartreuse3", cex=6)
points(dots$x[5:8], dots$y[5:8], pch=15, col="chartreuse3", cex=6)
points(dots$x[9:13], dots$y[9:13], pch=17, col="chartreuse", cex=6)
points(dots$x[14:18], dots$y[14:18], pch=17, col="chartreuse", cex=6)

在此处输入图片说明

Your function repelled_points creates a point pattern (object of class "ppp" in the spatstat package).您的函数repelled_points创建一个点模式( spatstat包中的"ppp"类对象)。 To learn how to plot it, read the help for plot.ppp .要了解如何绘制它,请阅读plot.ppp的帮助。 To select subsets, read the help for [.ppp .要选择子集,请阅读[.ppp的帮助。

dots <- repelled_points(18, 1, 0.35)
plot(Window(dots), type="n", main="")
plot(dots[1:4], pch=16, cols="chartreuse3", cex=6, add=TRUE)

Line 2 uses plot.owin and line 3 uses plot.ppp .第 2 行使用plot.owin ,第 3 行使用plot.ppp

In this code I have assumed that you specifically wanted the first 4 points in the pattern to be plotted with the specified parameters.在此代码中,我假设您特别希望使用指定参数绘制模式中的前 4 个点。

More commonly, people want to use different graphical symbols to represent points with different "attributes".更常见的是,人们希望使用不同的图形符号来表示具有不同“属性”的点。 Perhaps the points are classified into several different types, and points of type 1 should always be plotted with a square, type 2 with a triangle, etc. In spatstat the attributes of the points would be encoded as "marks" of the point pattern.也许这些点被分为几种不同的类型,类型 1 的点应该总是用正方形绘制,类型 2 用三角形等spatstat 。在spatstat中,点的属性将被编码为点模式的“标记”。 Then you could replace the three code lines above by a single line which calls plot.ppp with the required graphical information that maps the marks to symbols.然后你可以用一行调用plot.ppp替换上面的三行代码,其中包含将标记映射到符号的所需图形信息。 See the examples in the help for plot.ppp .请参阅plot.ppp帮助中的plot.ppp

See chapter 4 in the spatstat book for detailed information.有关详细信息,请参阅spatstat 书中的第 4 章。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM