install.packages("fmsb")
library(fmsb)
install.packages("RColorBrewer")
library(RColorBrewer) # 更多颜色选择,包括色盲友好的颜色
创建作图数据:
myradar <- data.frame(
treatments = c("Wt_DMSO", "APOE_DMSO", "10 uM Donepezil"),
A = c(100, 127.0712663, 75.49221394),
B = c(100, 54.20588761, 141.1077757),
C = c(100, 53.38809628, 146.3203228),
D = c(100, 200.15486, 64.33077449),
E = c(100, 174.32634, 157.0577396),
F = c(100, 148.8633135, 116.4686715))
myradar
rownames(myradar) <- paste(myradar$treatments) # 更改行的名称
myradar <- rbind(rep(300, 7), rep(0, 7), myradar) # 数据中增加2行,构建后续雷达图的框架
myradar
op <- par(mar = c(1, 2, 2, 1), mfrow = c(2, 2)) # 更改图片排列
radarchart(myradar[, -1],
title = "1")
radarchart(myradar[, -1],
axistype = 1, # 坐标轴类型
seg = 5, # 坐标轴分几段
pty = 32, # # 点的类型,16为默认实现圆点,32为无点。
plty = 2, plwd = 3, # 图的线条种类和粗细
title = "2")
radarchart(myradar[, -1],
axistype = 2, # 坐标轴类型
caxislabels = c("worst", "", "", "", "best"),
title = "3")
radarchart(myradar[, -1],
cglty = 2, # grid的类型
cglwd = 1.2, # grid的类型
cglcol = "grey", # grid的颜色
vlabels = c("a", "b", "c", "d", "e", "f"),
title = "4")
par(op) # 恢复到默认图片排列
display.brewer.all(colorblindFriendly = TRUE)
# 选择喜欢的调色盘
colors <- brewer.pal(3, "Dark2")
# 画出雷达图
radarchart(myradar[, -1],
axistype = 1, seg = 6,
pty = 18,
pcol = colors,
pfcol = scales::alpha(colors, 0.3),
plwd = 0.6,
plty = 1,
cglcol = "grey",
cglty = 1,
axislabcol = "black",
cglwd = 0.8,
caxislabels = c(0, 50, 100, 150, 200, 250, 300),
vlcex = 1.5,
title = "My Radar Chart")
# 添加legend
legend(x = 0.6, y = 1.2, # legend的位置
legend = rownames(myradar[3:5, ]), # legend为3—5行的行名称
bty = "n",
pch = 20 ,
col = scales::alpha(colors, 0.6),
text.col = "black",
cex = 1,
pt.cex = 2 )
[1].https://cran.r-project.org/web/packages/fmsb/index.html