简体   繁体   English

密度均质秤 plot

[英]Homogenizing scale for density plot

I am making a series of plots from a point pattern (PPP) with the density (kernel) function.我正在从密度(内核)function 的点模式(PPP)制作一系列图。 I would like that the maximum plotted number is 200 in all cases and just the heatmap accordingly (two of the images only go up to 100).我希望在所有情况下的最大绘制数都是 200,并且只是相应的热图(其中两个图像只有 go 最多 100)。 I have not been able to find a solution to this problem using the R base plot.我无法使用 R 基础 plot 找到解决此问题的方法。

    Microglia_Density <- density(Microglia_PPP, sigma =0.1, equal.ribbon = TRUE, col = topo.colors, main = "")
plot(Microglia_Density, main = "Microglia density")

Astrocytes_Density <- density(Astrocytes_PPP, sigma =0.1, equal.ribbon = TRUE, col = topo.colors, main = "")
plot(Astrocytes_Density, main = "Astrocytes density")

Neurons_Density <- density(Neurons_PPP, sigma =0.1, equal.ribbon = TRUE, col = topo.colors, main = "")
plot(Neurons_Density, main = "Neuronal density")

I would appreciate recommendations.我会很感激建议。 Regards问候

图1

图 2

图 3

Since we don't have access to your data I simulate fake data in a square.由于我们无权访问您的数据,因此我在正方形中模拟了假数据。 There are several options to do what you want.有几种选择可以做你想做的事。 First you should know that density() is a generic function, so when you invoke it on a ppp like Microglia_PPP actually the function density.ppp() is invoked.首先你应该知道density()是一个通用的 function,所以当你在像Microglia_PPP这样的ppp上调用它时,实际上会调用 function density.ppp density.ppp() This function returns an im object (effectively a 2-d “image” of values).这个 function 返回一个im object(实际上是值的二维“图像”)。 You plot this with plot() which in turn calls plot.im() , so you should read the help file of plot.im() , where it says that the argument col controls the colours used in the plot. You plot this with plot() which in turn calls plot.im() , so you should read the help file of plot.im() , where it says that the argument col controls the colours used in the plot. Either you can make a colour map covering the range of values you are interested in and supply that, or if you know that one of the images has the colour map you want to use you can save it and reuse for the others:您可以制作颜色 map 覆盖您感兴趣的值范围并提供该颜色,或者如果您知道其中一个图像具有您想要使用的颜色 map,您可以保存它并为其他图像重复使用:

library(spatstat)
set.seed(42)
Microglia_PPP <- runifpoint(100)
Neurons_PPP <- runifpoint(200)
Neurons_Density <- density(Neurons_PPP, sigma = 0.1)
Microglia_Density <- density(Microglia_PPP, sigma = 0.1)
my_colourmap <- plot(Neurons_Density, main = "Neuronal density", col = topo.colors)

plot(Microglia_Density, main = "Microglia density", col = my_colourmap)

Notice the colour maps are the same, but it only covers the range from approximately 80 to 310. Any values of the image outside this range will not be plottet, so they appear white.请注意,颜色图是相同的,但仅涵盖大约 80 到 310 的范围。超出此范围的图像的任何值都不会被绘制,因此它们显示为白色。

You can make a colour map first and then use it for all the plots (see help(colourmap) ):您可以先制作颜色 map,然后将其用于所有绘图(请参阅help(colourmap) ):

my_colourmap <- colourmap(topo.colors(256), range = c(40,315))
plot(Neurons_Density, main = "Neuronal density", col = my_colourmap)

plot(Microglia_Density, main = "Microglia density", col = my_colourmap)

Finally another solution if you want the images side by side is to make them an imlist (image list) and use plot.imlist() with equal.ribbon = TRUE :最后,如果您希望图像并排,另一种解决方案是将它们imlist (图像列表)并使用plot.imlist()equal.ribbon = TRUE

density_list <- as.imlist(list(Neurons_Density, Microglia_Density))
plot(density_list, equal.ribbon = TRUE, main = "")

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

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