# install.packages("fmsb")
library(fmsb)
package 'fmsb' successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\jhaow\AppData\Local\Temp\RtmpUdUuoC\downloaded_packages
Warning message:
"package 'fmsb' was built under R version 4.2.2"
pdata = data.frame(model1 = c(0.9, 0.93, 0.97, 0.95, 0.96, 0.99), Group = LETTERS[1:6])
pdata
value | Group |
---|---|
0.90 | A |
0.93 | B |
0.97 | C |
0.81 | D |
0.96 | E |
0.99 | F |
第一行必须为每列的最大值
第二行必须为每列的最小值
pdata2 = data.frame(t(pdata[, 1, drop = F]))
colnames(pdata2) = pdata$Group
pdata2 = rbind(Max = 1, Min = 0.8, pdata2); pdata2
A | B | C | D | E | F | |
---|---|---|---|---|---|---|
Max | 1.0 | 1.00 | 1.00 | 1.00 | 1.00 | 1.00 |
Min | 0.8 | 0.80 | 0.80 | 0.80 | 0.80 | 0.80 |
model1 | 0.9 | 0.93 | 0.97 | 0.95 | 0.96 | 0.99 |
radarchart(pdata2)
radarchart(
pdata2, axistype = 1, # 2为去除网络标签
# Customize the polygon
pcol = "#00AFBB", pfcol = scales::alpha("#00AFBB", 0.5), plwd = 2, plty = 1,
# Customize the grid
cglcol = "black", cglty = 2, # 2为虚线
cglwd = 2,
# Customize the axis
axislabcol = "black",
# Variable labels
vlcex = 2, vlabels = colnames(padta2),
caxislabels = seq(0.8, 1, 0.05))
padta3 = rbind(pdata2, model2 = c(0.95, 0.98, 0.89, 0.9, 0.90, 1)); padta3
A | B | C | D | E | F | |
---|---|---|---|---|---|---|
Max | 1.00 | 1.00 | 1.00 | 1.00 | 1.00 | 1.00 |
Min | 0.80 | 0.80 | 0.80 | 0.80 | 0.80 | 0.80 |
model1 | 0.90 | 0.93 | 0.97 | 0.95 | 0.96 | 0.99 |
model2 | 0.95 | 0.98 | 0.89 | 0.90 | 0.90 | 1.00 |
setOpts(7, 9)
# pdf("Radar2.pdf", 7, 9)
# par(oma=c(1,5,0,3))
radarchart(
padta3, axistype = 1,
# Customize the polygon
pcol = c("#00AFBB", "#E7B800"), pfcol = scales::alpha(c("#00AFBB", "#E7B800"),0.5), plwd = 2, plty = 1,
# Customize the grid
cglcol = "black", cglty = 2, cglwd = 0.8,
# Customize the axis
axislabcol = "black",
# Variable labels
vlcex = 1.5, vlabels = paste0(colnames(padta3), "\n", padta3[3, ], "/", padta3[4, ]),
caxislabels = seq(0.8, 1, 0.05))
# Add an horizontal legend
legend(
x = -0.95, y = -1.3, legend = rownames(padta3[-c(1,2),]), horiz = TRUE,
bty = "n", pch = 20 , col = c("#00AFBB", "#E7B800"),
text.col = "black", cex = 2, pt.cex = 3
)
# dev.off()
?radarchart
radarchart {fmsb} | R Documentation |
Drawing the radar chart with several lines from a data frame, which must be composed of more than 3 variables as axes and the rows indicate cases as series.
radarchart(df, axistype, seg, pty, pcol, plty, plwd, pdensity, pangle, pfcol,
cglty, cglwd, cglcol, axislabcol, title, maxmin, na.itp, centerzero,
vlabels, vlcex, caxislabels, calcex, paxislabels, palcex, ...)
df |
The data frame to be used to draw radarchart. If maxmin is TRUE, this must include maximum values as row 1 and minimum values as row 2 for each variables, and actual data should be given as row 3 and lower rows. The number of columns (variables) must be more than 2. |
axistype |
The type of axes, specified by any of 0:5. 0 means no axis label. 1 means center axis label only. 2 means around-the-chart label only. 3 means both center and around-the-chart (peripheral) labels. 4 is *.** format of 1, 5 is *.** format of 3. Default is 0. |
seg |
The number of segments for each axis (default 4). |
pty |
A vector to specify point symbol: Default 16 (closed circle), if you don't plot data points, it should be 32. This is repeatedly used for data series. |
pcol |
A vector of color codes for plot data: Default 1:8, which are repeatedly used. |
plty |
A vector of line types for plot data: Default 1:6, which are repeatedly used. |
plwd |
A vector of line widths for plot data: Default 1, which is repeatedly used. |
pdensity |
A vector of filling density of polygons: Default NULL, which is repeatedly used. |
pangle |
A vector of the angles of lines used as filling polygons: Default 45, which is repeatedly used. |
pfcol |
A vector of color codes for filling polygons: Default NA, which is repeatedly usd. |
cglty |
Line type for radar grids: Default 3, which means dotted line. |
cglwd |
Line width for radar grids: Default 1, which means thinnest line. |
cglcol |
Line color for radar grids: Default "navy" |
axislabcol |
Color of axis label and numbers: Default "blue" |
title |
if any, title should be typed. |
maxmin |
Logical. If true, data frame includes possible maximum values as row 1 and possible minimum values as row 2. If false, the maximum and minimum values for each axis will be calculated as actual maximum and minimum of the data. Default TRUE. |
na.itp |
Logical. If true, items with NA values are interpolated from nearest neighbor items and connect them. If false, items with NA are treated as the origin (but not pointed, only connected with lines). Default FALSE. |
centerzero |
Logical. If true, this function draws charts with scaling originated from (0,0). If false, charts originated from (1/segments). Default FALSE. |
vlabels |
Character vector for the names for variables. If NULL, the names of the variables as colnames(df) are used. Default NULL. |
vlcex |
Font size magnification for vlabels. If NULL, the font size is fixed at text()'s default. Default NULL. |
caxislabels |
Character vector for center axis labels, overwriting values specified in axistype option. If NULL, the values specified by axistype option are used. Default is NULL. |
calcex |
Font size magnification for caxislabels. If NULL, the font size is fixed at text()'s default. Default NULL. |
paxislabels |
Character vector for around-the-chart (peripheral) labels, overwriting values specified in axistype option. If NULL, the values specified by axistype option are used. Default is NULL. |
palcex |
Font size magnification for paxislabels. If NULL, the font size is fixed at text()'s default. Default NULL. |
... |
Miscellaneous arguments to be given for plot.default(). |
No value is returned.
Minato Nakazawa [email protected] https://minato.sip21c.org/
# Data must be given as the data frame, where the first cases show maximum.
maxmin <- data.frame(
total=c(5, 1),
phys=c(15, 3),
psycho=c(3, 0),
social=c(5, 1),
env=c(5, 1))
# data for radarchart function version 1 series, minimum value must be omitted from above.
RNGkind("Mersenne-Twister")
set.seed(123)
dat <- data.frame(
total=runif(3, 1, 5),
phys=rnorm(3, 10, 2),
psycho=c(0.5, NA, 3),
social=runif(3, 1, 5),
env=c(5, 2.5, 4))
dat <- rbind(maxmin,dat)
op <- par(mar=c(1, 2, 2, 1),mfrow=c(2, 2))
radarchart(dat, axistype=1, seg=5, plty=1, vlabels=c("Total\nQOL", "Physical\naspects",
"Phychological\naspects", "Social\naspects", "Environmental\naspects"),
title="(axis=1, 5 segments, with specified vlabels)", vlcex=0.5)
radarchart(dat, axistype=2, pcol=topo.colors(3), plty=1, pdensity=c(5, 10, 30),
pangle=c(10, 45, 120), pfcol=topo.colors(3),
title="(topo.colors, fill, axis=2)")
radarchart(dat, axistype=3, pty=32, plty=1, axislabcol="grey", na.itp=FALSE,
title="(no points, axis=3, na.itp=FALSE)")
radarchart(dat, axistype=1, plwd=1:5, pcol=1, centerzero=TRUE,
seg=4, caxislabels=c("worst", "", "", "", "best"),
title="(use lty and lwd but b/w, axis=1,\n centerzero=TRUE, with centerlabels)")
par(op)
参考:https://zhuanlan.zhihu.com/p/464010168