小编may*_*cca的帖子

NetLogo:TO-REPORT的含义是为假人解释的?

我有一个问题需要理解to-reportreport在NetLogo中的作用,即使它看起来非常有用,我也无法找到用"人类风格"语言编写的帮助.

在NetLogo dictionnary http://ccl.northwestern.edu/netlogo/docs/dictionary.html#report中 我可以找到以下定义to-report:

to-report procedure-name
to-report procedure-name [input1 ...]
Used to begin a reporter procedure.

The body of the procedure should use report to report a value for the procedure. See report. 
Run Code Online (Sandbox Code Playgroud)

并为report:

report value
Immediately exits from the current to-report procedure and reports value as the result of that procedure. report and to-report are always used in conjunction with each other. See to-report for a discussion of how to …
Run Code Online (Sandbox Code Playgroud)

patch report netlogo

8
推荐指数
1
解决办法
2084
查看次数

如何计算由包含x,y的矩阵定义的两点之间的欧几里得距离?

我在欧氏距离计算中非常迷失.我发现函数dist2 {SpatialTools}或rdist {fields}来执行此操作,但它们不能按预期工作.

我想一个点在carthesian系统中有两个坐标,所以[x,y].要测量2个点之间的距离(由行定义),我需要2个点的4个坐标,所以点A:[x1,y1]点B:[x2,y2]

积分协调:

积分位置

A[0,1]
B[0,0] 
C[1,1]
D[1,1]
Run Code Online (Sandbox Code Playgroud)

我有两个矩阵:x1(A和C在那里,由行定义)和x2(包含B和D).写在矩阵中:

library("SpatialTools")
x1<-matrix(c(0,1,1,1), nrow = 2, ncol=2, byrow=TRUE)
x2<-matrix(c(0,0,1,1), nrow = 2, ncol=2, byrow=TRUE)
Run Code Online (Sandbox Code Playgroud)

所以我得到了

> x1
     [,1] [,2]
[1,]    0    1    #(as xy coordinates of A point)
[2,]    1    1    #(same for C point)

> x2
     [,1] [,2]
[1,]    0    0    #(same for B point)
[2,]    1    1    #(same for D point)
Run Code Online (Sandbox Code Playgroud)

计算之间的欧氏距离

A <-> B  # same as x1[1,] <-> x2[1,]
C <-> …
Run Code Online (Sandbox Code Playgroud)

r matrix euclidean-distance

7
推荐指数
1
解决办法
4万
查看次数

ggplot2:在绘图区域外绘制 geom_segment()

我在 ggplot2 中创建了两个方面图。我想在绘图区域外添加一个箭头。多个问题试图解决这个问题: How to draw lines out of plot area in ggplot2? 在 ggplot2 生成的图下方显示文本

但我不能让我的例子工作。另外,我希望有一种更简单的方法来实现这一点?

我试图增加plot.margins和使用coord_cartesian(),但都没有帮助。

在此处输入图片说明

相反,我想要:

在此处输入图片说明

我的虚拟示例:

# read library to assess free data
library(reshape2)
library(ggplot2)


ggplot(tips,
       aes(x=total_bill,
           y=tip/total_bill)) + 
  geom_point(shape=1) +
  facet_grid(. ~ sex) +
  # define the segment outside the plot
  geom_segment(aes(x = 10, 
                   y = -0.25, 
                   xend = 10, 
                   yend = 0),
               col = "red",
               arrow = arrow(length = unit(0.3, "cm"))) +
  theme_bw() +
  # limit the displayed plot extent …
Run Code Online (Sandbox Code Playgroud)

r ggplot2

6
推荐指数
1
解决办法
3889
查看次数

移动窗口的地图精度评估

我想使用分类Landsat图像和参考数据集之间的混淆矩阵进行准确性评估.地图具有相同的分辨率和范围.我想逐像素地评估协议.在许多研究中,我发现他们使用移动内核窗口(理想的3x3)来"处理"Landsat像素的重合失调.但是我无法找到任何方法来使用这个移动窗口进行R中的混淆矩阵评估,通常它用于值插值.

您是否有任何想法如何将移动窗口实施到分类准确度评估中?或者我误解了这种方法?

非常感谢,

例:

library("raster")
clas <- raster(ncols=5, nrows=5)
values(clas)<-c(2,1,0,0,1,
         2,1,0,0,0,
         1,0,0,0,0,
         0,0,0,0,0,
         2,1,0,0,2)
reference <- raster(ncols=5, nrows=5)
values(reference)<-c(2,1,0,0,0,
         2,1,0,0,1,
         0,0,0,0,0,
         1,2,0,0,2,
         0,0,0,0,0)
Run Code Online (Sandbox Code Playgroud)

r raster r-raster

5
推荐指数
0
解决办法
171
查看次数

使用ggplot和基本绘图函数获得不同的结果

我在这里有一张桌子:http://ulozto.cz/xAeP3Ahn/res2-txt.我试图从中得出一个点图.

我读了我的桌子:

res2<-read.table("res2.txt", header = TRUE, sep="\t")
Run Code Online (Sandbox Code Playgroud)

并创建2个图.

(1)这是单个绘图功能的脚本:

plot(res2$V2, res2$dist06, type = "n")
points(subset(res2$V2, year == 2006), subset(res2$dist06, year == 2006), pch = 19, col   = "red", cex = 1)
points(subset(res2$V2, year == 2007), subset(res2$dist06, year == 2007), pch = 19, col = "green", cex = 1)
points(subset(res2$V2, year == 2008), subset(res2$dist06, year == 2008), pch = 19, col = "black", cex = 1)
points(subset(res2$V2, year == 2009), subset(res2$dist06, year == 2009), pch = 19, …
Run Code Online (Sandbox Code Playgroud)

charts plot r subset

5
推荐指数
1
解决办法
254
查看次数

使用facet_grid为我的因子添加"标题"

我想使用ggplot2为我的因素添加文本/标题.

例如来自{reshape2}库的数据:

library(reshape2)
library(ggplot2)
ggplot(tips, aes(x=total_bill, y=tip/total_bill)) + geom_point(shape=1) +
   facet_grid(sex ~ .)
Run Code Online (Sandbox Code Playgroud)

因素标签是:女性和男性.

我怎样才能在它们上面加上标题"性"?

在此输入图像描述

plot r ggplot2

5
推荐指数
1
解决办法
983
查看次数

R radarchart:自由轴增强记录显示?

我正在尝试使用显示我的数据radarchart {fmsb}.我的记录值变化很大.因此,在最终图中看不到低值.

是否每个记录都有"自由"轴,以便独立于其比例显示数据?

虚拟的例子:

df<-data.frame(n = c(100, 0,0.3,60,0.3),
               j = c(100,0, 0.001, 70,7),
               v = c(100,0, 0.001, 79, 3),
               z = c(100,0, 0.001, 80, 99))

      n     j       v       z
1 100.0 100.0 100.000 100.000   # max
2   0.0   0.0   0.000   0.000   # min
3   0.3 0.001   0.001   0.001   # small values -> no visible on final chart!!
4  60.0 0.001  79.000  80.000   
5   0.3   0.0   3.000  99.000
Run Code Online (Sandbox Code Playgroud)

创建雷达图

require(fmsb)
radarchart(df, axistype=0, pty=32, axislabcol="grey",# na.itp=FALSE,
           seg = 5, centerzero …
Run Code Online (Sandbox Code Playgroud)

r radar-chart

5
推荐指数
1
解决办法
475
查看次数

如果按组缺少数据,则方框图的宽度是否一致?

我有一个类似的问题,以前针对条形图讨论,但缺少框形图的解决方案:如果缺少数据,则geom_bar的宽度一致

我想按小组制作箱形图。但是,某些组的数据可能会丢失,从而导致具有丢失组的箱线图的宽度增加

我尝试指定geom_boxplot(width = value)或geom_boxplot(varwidth = F),但这不起作用。

另外,如Barplots示例所建议,我尝试NA为缺少的数据组添加值。Boxplot仅跳过缺少的数据,并扩展boxplot的宽度。我得到了警告:

Warning messages:
1: Removed 1 rows containing non-finite values (stat_boxplot). 
Run Code Online (Sandbox Code Playgroud)

虚拟示例:

# library
library(ggplot2)

# create a data frame
variety=rep(LETTERS[1:7], each=40)
treatment=rep(c("high","low"),each=20)
note=seq(1:280)+sample(1:150, 280, replace=T)

# put data together
data=data.frame(variety, treatment ,  note)

ggplot(data, aes(x=variety, y=note, fill=treatment)) + 
  geom_boxplot()
Run Code Online (Sandbox Code Playgroud)

如果每个组都有值,则箱线图具有相同的宽度:

箱线图具有相同的宽度,每个组都有值

删除1组的值:

# subset the data to have a missing data for group: …
Run Code Online (Sandbox Code Playgroud)

r ggplot2 boxplot

5
推荐指数
1
解决办法
699
查看次数

R ggpubr:按组添加平均水平线和配对比较?

我最近发现了很棒的ggpubr包。当我与多个小组合作时,我喜欢将数据分成多个方面(facet.by )。

我的问题由两个子问题组成,与同一个图表相关。我想

  1. 每组添加唯一的平均水平线,并且
  2. 仅绘制按组进行的显着比较

我的目标是显示箱线图及其成对比较显着性值。由于各组的显着性可能不同,因此我可以仅绘制显着组,或指定显着比较,并按组单独绘制它们。

示例数据:

library(ggpubr)
library(ggplot2)  

# Create data
# :::::::::::::::::::::::::::::::::::::::::::::::::::
data("ToothGrowth")
df <- ToothGrowth

# Create basic plot
p <- ggboxplot(df, 
               x = "dose", 
               y = "len",
               color = "dose", 
               palette =c("#00AFBB", "#E7B800", "#FC4E07"),
               add = "jitter",
               facet.by = "supp", # define faceting 
               shape = "dose")

# Add horizontal line per each group???
p + geom_hline(yintercept = mean(df$len), #aggregate(len ~ supp, df, mean)$len, # mean(df$len), 
               linetype = 2,
               group = "supp")
Run Code Online (Sandbox Code Playgroud)

导致 …

statistics comparison r boxplot

4
推荐指数
1
解决办法
6034
查看次数

R:缺少值组合的完整数据帧

我有一个简单的问题,我无法弄清楚.我有一个包含两个因子(distance)和年(years)的数据帧.我想years用0 来完成每个因子的所有值.

即从这个:

    distance years area
1      NPR     3   10
2      NPR     4   20
3      NPR     7   30
4      100     1   40
5      100     5   50
6      100     6   60
Run Code Online (Sandbox Code Playgroud)

得到这个:

   distance years area
1       NPR     1    0
2       NPR     2    0
3       NPR     3   10
4       NPR     4   20
5       NPR     5    0
6       NPR     6    0
7       NPR     7   30
8       100     1   40
9       100     2    0
10      100     3    0 …
Run Code Online (Sandbox Code Playgroud)

r tidyr

4
推荐指数
1
解决办法
1186
查看次数