使用最新版的 ggradar2 自由地绘制雷达图(蜘蛛图)

Github链接

Gitee链接

一、安装ggradar2

在R软件(或Rstudio)中,使用以下方法安装。

方法1:from github

install.packages(“devtools”)

devtools::install_github(“PhDMeiwp/ggradar2”, dependencies = TRUE)

方法2:from gitee (国内可用)

install.packages(“git2r”)

install.packages(“remotes”)

library(git2r)

library(remotes)

remotes::install_git(“https://gitee.com/meiweiping/ggradar2.git”)

方法3:先从Github或gitee下载.Zip 或 .tar.gz 文件到电脑本地,然后安装

devtools::install_local(“E:/R/ggradar2/ggradar2-master.zip”) # zip文件

devtools::install_local(“E:/R/ggradar2/ggradar2_0.3.tar.gz”) # tar.gz文件

注意要将上述路径改成你自己的路径。

二、使用ggradar2

先加载 ggradar2 函数包

library(ggradar2)

案例1 (one group)如下:

df <- data.frame(

NAME = ‘G1’,

A = 0.4, B = 0.8, C = 0.5, D = 0.8, E = 0.5)

ggradar2(df)

example1.png

案例2 (grid line setting)如下:

df <- data.frame(

NAME = ‘G1’,

A = 123, B = 65, C = 157, D = 181, E = 99 )

ggradar2(df,

# radar values

values.radar = c(“0”, “50”, “100”, “150”, “”, “200”),

# centre position

centre.y = 0,

# grid lines

gridline.n2.colour = “blue”,

gridline.n4.colour = “blue”,

# grid labels

gridline.label.offset.y = 0,

# axis labels

axis.label.offset = 1.2

)

example2.png

案例 3 (multiple groups)如下:

df <- data.frame(

NAME = c(‘G1’, ‘G2’, ‘G3’),

A = c(0.2, 0.4, 0.5), B = c(0.3, 0.6, 0.3),

C = c(0.7, 0.3, 0.5), D = c(0.4, 0.8, 0.2), E = c(0.5, 0.6, 0.3))

ggradar2(df)

example3.png

案例 4 (fill setting) 如下:

df <- data.frame(

NAME = c(‘G1’, ‘G2’, ‘G3’),

A = c(2, 4, 5), B = c(3, 6, 3),

C = c(7, 3, 5), D = c(4, 8, 2), E = c(5, 6, 3))

ggradar2(df,

values.radar = c(“0”, “2”, “4”, “6”, “8”, “10”),

grid.line.width = 0.3,

# group parameters

group.line.width = 0.5,

group.point.size = 2,

group.colours = c(“red”,”orange”,”green”),

fill = TRUE,

fill.alpha = 0.2,

axis.label.offset = 1.15,

axis.label.size = 4,

background.circle.colour = “white” )

example4.png

案例 5 (default ggradar plot) 如下:

df <- data.frame(

NAME = ‘G1’,

A = 0.4, B = 0.8, C = 0.5, D = 0.8, E = 0.5 )

ggradar2(df,

# radar values

values.radar = c(“0%”, “50%”, “”, “”, “”, “100%”),

# grid labels

grid.label.color = “#000000”,

grid.label.size = 6,

gridline.label.offset.x = -0.1,

gridline.n2.colour = “#007A87”,

# group

group.point.size = 6

)

example5.png

三、重要说明

ggradar2函数包的版权,归ggradar函数包原作者Ricardo Bion 所有,本人只是众多的贡献者之一。

Leave a Reply

Your email address will not be published. Required fields are marked *

科研杂谈,如涉及版权问题请联系 [email protected]