是否可以使用使用两列返回一列的自定义函数进行聚合?
假设我有一个数据帧:
x <- c(2,4,3,1,5,7)
y <- c(3,2,6,3,4,6)
group <- c("A","A","A","A","B","B")
data <- data.frame(group, x, y)
data
#   group x y
# 1     A 2 3
# 2     A 4 2
# 3     A 3 6
# 4     A 1 3
# 5     B 5 4
# 6     B 7 6
Run Code Online (Sandbox Code Playgroud)
我有我想要在两列(x和y)上使用的函数:
pathlength <- function(xy) {
  out <- as.matrix(dist(xy))
  sum(out[row(out) - col(out) == 1])
}
Run Code Online (Sandbox Code Playgroud)
我用聚合尝试了以下内容:
out <- aggregate(cbind(x, y) ~ group, data, FUN = pathlength)  
out <- aggregate(cbind(x, y) …Run Code Online (Sandbox Code Playgroud) 正如您在此示例中看到的,我正在尝试绘制多个雷达图。但是,圆周轴标签正在被截断。我试过将 mar 和 oma 指定为标准,但没有任何运气。
其他人能解决这个问题吗?
require(fmsb)
df <- data.frame(
  a = c(0.5, 0, 0.3),
  stopcuttingmeoff = c(1.2, 0, 0.5),
  c = c(0.25, 0, 0.1),
  d = c(0.25, 0, 0.1),
  dontcutmeoff = c(4, 0, 2))
par(mfrow=n2mfrow(4))
radarchart(df, axistype = 2, centerzero = TRUE, palcex = 0.9)
radarchart(df, axistype = 2, centerzero = TRUE, palcex = 0.9)
radarchart(df, axistype = 2, centerzero = TRUE, palcex = 0.9)
radarchart(df, axistype = 2, centerzero = TRUE, palcex = 0.9)
Run Code Online (Sandbox Code Playgroud)
