您可以使用fmsb 包。
library(fmsb)
library(dplyr)
# Group names needs to be as row names of data.frame
x <- maxmin %>%
mutate(name = paste(fut, group, sep = "_")) %>%
select(-c(fut, group))
df <- as.data.frame(x %>% select(-c(name)))
rownames(df) <- x$name
# max & min needs to be added as first and second row, respectively
df <- rbind(rep(20,5) , rep(0,5) , df)
par(mar=rep(0.8,4))
par(mfrow=c(1,2))
radarchart(df[c(1:2, 3:4), ], title = "I")
radarchart(df[c(1:2, 5:6), ], title = "M")
resulting graph
编辑:
合而为一:
## All in one
library(fmsb)
library(dplyr)
# Group names needs to be as row names of data.frame
x <- maxmin %>%
mutate(name = paste(fut, group, sep = "_")) %>%
select(-c(fut, group))
df <- as.data.frame(x %>% select(-c(name)))
rownames(df) <- x$name
# max & min needs to be added as first and second row, respectively
df <- rbind(rep(20,5) , rep(0,5) , df)
radarchart(df,
pcol = c("steelblue", "steelblue", "tomato", "tomato"), # colors define Group
plty = c(1, 2, 1, 2), # line type defines fut
plwd = 2) # line width
# Add a legend
legend(x=0.7, y=1, legend = rownames(df[-c(1,2),]), bty = "n", pch=20 , col = c("steelblue", "steelblue", "tomato", "tomato"), text.col = "grey", cex=1.1, pt.cex=2)
添加:新数据集的示例:
对于radarchart,您需要有data.frame,其中包含列中的变量和行中的组。因此,对于您的特定数据集data,您需要创建 3 个单独的图(FClog、pvalue、count)。
以下是 FClog 的示例:
#Example with new dataset "data"
library(fmsb)
library(dplyr)
library(tidyr)
set.seed(100) # you may want to set this for reproducibility example
data <- data.frame(da = c("total", "phys","psycho","social","fut", "total","phys", "psycho","social","fut"), logFC = runif(10, -1, 1), pvalue = runif(10, max= 0.05, min= 0.001), count = runif(10,max = 20, min = 12), group = rep(c("WT","KO"), each = 5))
x1 <- data %>% select(da, logFC, group) %>%
pivot_wider(names_from = group, values_from = logFC) %>%
as.data.frame()
rownames(x1) <- x1[,1]
x1 <- x1[,2:ncol(x1)]
x1 <- x1 %>%
t() %>%
as.data.frame()
# max & min needs to be added as first and second row, respectively
df <- rbind(rep(1,ncol(x1)) , rep(-1,ncol(x1)) , x1)
par(mar=rep(0.8,4))
radarchart(df,
title = "FClog",
pcol = c("steelblue", "tomato"), # colors define Group
plty = c(1, 2), # line type defines fut
plwd = 2) # line width
# Add a legend
legend(x=0.7, y=1, legend = rownames(df[-c(1,2),]), bty = "n", pch=20 , col = c("steelblue", "tomato"), text.col = "grey", cex=1.1, pt.cex=2)