【发布时间】:2018-05-22 03:21:10
【问题描述】:
这是我之前的帖子:How to measure the area of a polygon in ggplot2?
我现在想做的是将生成的雷达图用作完全独立散点图中的数据点,或者可能保存对象并稍后在图表上使用它来描绘实际数据的形状。
我有很多文件,它们通常看起来像这样。它们的列数从 1 到 many 不等,分数始终采用降序格式。即 #1 总是在任何给定文件中贡献最多。
myfile
01 0.31707317
02 0.12195122
03 0.09756098
04 0.07317073
05 0.07317073
06 0.07317073
07 0.07317073
08 0.07317073
09 0.04878049
10 0.04878049
在这里,我想为这些文件中的每一个单独绘制一个雷达图,然后得到一个没有网格的形状。 ggradar 是我找到的最接近和最好的。
ggradar(as.matrix(t(radar)), group.point.size = 2, grid.line.width = 0, grid.max = 1.0, grid.mid = 0,
grid.min = 0, axis.line.colour = "white", axis.label.size = 0, grid.label.size = 0,
centre.y = 0, background.circle.colour = "white", group.colours = "black", group.line.width = 1)
现在,当我想将这些形状用作数据点时,问题就开始了。
@brian 友好地评论并暗示了如何解决这个问题。
R::ggplot2::geom_points: how to swap points with pie charts?
Small ggplot2 plots placed on coordinates on a ggmap
受这些 cmets 的启发,我现在可以将绘图与文件名一起保存为一列,并使用同一管道继续添加新文件。
for (file in file_list){
#eliminate the empty files (they contain only the header)
if (file.size(file) > 420){
# if the merged dataset does exist, append to it
if (exists("dfradar")){
radarfile <-read.table(file, header=TRUE, sep="\t")
radarfile1 <- as.data.frame(as.numeric(radarfile[,3]))
rownames(radarfile1) <- c(1:nrow(radarfile))
dfradar1 <- ggradar(t(radarfile1), group.point.size = 1, grid.line.width = 0, grid.max = 1, grid.mid = 0,
grid.min = 0, axis.line.colour = "white", axis.label.size = 0, grid.label.size = 0,
centre.y = 0, background.circle.colour = "white", group.colours = "black", group.line.width = 0.5) +
theme(legend.position = "none")
dfradar1 <- cbind(substring(file,11), dfradar1)
dfradar <- rbind(dfradar, dfradar1)
}
# if the merged dataset doesn't exist, create it
if (!exists("dfradar")){
radarfile <- read.table(file, header=TRUE, sep="\t")
radarfile1 <- as.data.frame(as.numeric(radarfile[,3]))
rownames(radarfile1) <- c(1:nrow(radarfile))
dfradar <- ggradar(t(radarfile1), group.point.size = 1, grid.line.width = 0, grid.max = 1, grid.mid = 0,
grid.min = 0, axis.line.colour = "white", axis.label.size = 0, grid.label.size = 0,
centre.y = 0, background.circle.colour = "white", group.colours = "black", group.line.width = 0.5) +
theme(legend.position = "none")
dfradar <- cbind(substring(file,11), dfradar)
rm(radarfile)
rm(radarfile1)
}
} }
现在当我想保存 grobs 时,我不能;我明白了:
“mutate_impl(.data, dots) 中的错误:评估错误:尝试 应用非函数。”
或:
“plot_clone(plot) 中的错误:尝试应用非函数”
# merge the df with another df containing all other
# variables that I wanna use in my scatterplot
dfradar_merge <- merge(dfradar, Cases, all=FALSE)
dfradar_merge <- dfradar_merge %>% mutate(radargrobs = list(annotation_custom(ggplotGrob(radarplots)),
xmin = as.numeric(Gender), xmax = as.numeric(Gender)*1.2,
ymin = as.numeric(Age) , ymax = as.numeric(Age)*1.2)))
我想如果我能把这部分弄清楚,并将变量作为 xmin 和 ymin 传递,我应该能够做我需要的......
非常感谢任何想法。这让我很头疼。
【问题讨论】:
标签: r plot ggplot2 visualization radar-chart