我在 R 中的雷达图有点问题。即使情节很好,我也收到以下警告:
> source('~/.active-rstudio-document')
Warning message:
In `levels<-`(`*tmp*`, value = if (nl == nL) as.character(labels) else paste0(labels, :
duplicated levels in factors are deprecated
> radar
Warning messages:
1: In `levels<-`(`*tmp*`, value = if (nl == nL) as.character(labels) else paste0(labels, :
duplicated levels in factors are deprecated
2: In `levels<-`(`*tmp*`, value = if (nl == nL) as.character(labels) else paste0(labels, :
duplicated levels in factors are deprecated
我在其他帖子中看到了同样的错误,但我真的不明白如何将答案应用于我的数据集......
这是我的数据集
MSF,C1,2
OCA,C1,6
SIOA,C1,4
CCFF,C1,4
MSF,C2,4
OCA,C2,2
SIOA,C2,6
CCFF,C2,2
MSF,C3,6
OCA,C3,6
SIOA,C3,6
CCFF,C3,6
这是相应雷达图的代码(可能只有我定义数据集的第一部分是相关的,但是是的......这就是我迷路的地方):
colnames(dataset) = c("type", "variable", "value")
dataset$value = as.numeric(dataset$value)
dataset$variable <- factor(dataset$variable, levels = rev(dataset$variable), ordered=TRUE)
# Radar function ------------------------------------------------------------
coord_radar <- function (theta = "x", start = 0, direction = 1) {
theta <- match.arg(theta, c("x", "y"))
r <- if (theta == "x")
"y"
else "x"
ggproto("CordRadar", CoordPolar, theta = theta, r = r, start = start,
direction = sign(direction),
is_linear = function(coord) TRUE)
}
# Radar plot ------------------------------------------------------------
radar <- ggplot(dataset, aes(x = variable, y = value, group=type)) +
geom_polygon(aes(group = type, color=type,fill=type), size = 1, alpha=0.1) +
scale_fill_manual(values=cbPalette) +
geom_line(aes(group = type, color=type)) +
scale_colour_manual(values = cbPalette) +
coord_radar()