knitr::opts_chunk$set(echo = TRUE)

Radar charts (spider, polar, web, or star) are a way to display multivariate data using single or composed figures (one radar or multiple radars). In these kinds of graphs, there are as many axes as variables or cases; therefore, the shape depends on the number of variables (cases or samples) considered.

The figures made here can be used for comparing values quickly since they are all centered, and the polygons formed by the union of dots (or between polygons) have clear shapes. In cases where there are multiple variables, it is most common to transform their values through the normalization method, since it provides a range of values between 0 and 1, and it is unnecessary to check assumptions about the data distribution or to use multiple transformation methods to get a range of positive values.

RadChart offers three different ways to plot radar charts. First, the plot vector values option has a mandatory argument (Vec) that specifies the main title. The second option allows for the plotting of multiple radar charts using data frames, with the graphic function par and parameter mfrow (to set the rows and columns). In the above options, col1 and col2 are required; however, in the third option, col2 must be absent, because the colors are automatically supplied. The last option presents a radar chart with a minimum of three variables, samples, or stations. For the multivariate option of RadChart (third option), the argument “MV” is mandatory, which provides the main title.

In keyanswers’ github repository, this function is available on https://github.com/Keyanswers/RadChart/blob/main/RadChartFunction.R, and it has an introductory video on https://www.youtube.com/watch?v=rY4aEG9zqw0&t=44s&ab_channel=Keyanswers.

Function Arguments

RadChart(df,Ftext, col1, col2, Vec, MV)

Note: When it runs empty, the RadChart function returns the error “the argument df is missing, with no default value default”; however, with this argument, the function works as expected.

Below are examples of different radar charts generated from the data sets which are available as examples in the global environment of R.

Loading data for plotting

Dataset OrchardSprays

data(OrchardSprays);
knitr::kable(
  head(OrchardSprays), 
  caption = "Data frame of OrchardSprays dataset"
)
Data frame of OrchardSprays dataset
decrease rowpos colpos treatment
57 1 1 D
95 2 1 E
8 3 1 B
69 4 1 H
92 5 1 G
90 6 1 F

In this example, a vector was created using six values from the decrease column.

par(mfrow=c(1,1))
decrease=OrchardSprays$decrease[1:6]
decrease
## [1] 57 95  8 69 92 90
  • Option one
RadChart(decrease,"Perpetua Titling MT","black","dodgerblue",Vec="Decrease")
## Loading required package: fmsb
## Loading required package: extrafont
## Registering fonts with R
## Loading required package: extrafontdb
## Loading required package: scales
## Warning: package 'scales' was built under R version 4.1.2
## Loading required package: caret
## Loading required package: ggplot2
## Loading required package: lattice
## Registered S3 methods overwritten by 'pROC':
##   method    from
##   print.roc fmsb
##   plot.roc  fmsb
## Loading required package: Rttf2pt1
## [1] "Plotting"

  • Option two
par(mfrow=c(2,2))
RadChart(OrchardSprays[c(1:3,9:15),1:3],"Niagara Engraved","black","brown4")
## [1] "Plotting"

  • Option three
par(mfrow=c(1,1))
RadChart(OrchardSprays[c(1:2,9:11),1:3],"Malgun Gothic","black",MV="OrchardSprays Dataset")
## [1] "Plotting"

Dataset Orange

As a simple example of the vector option, the first column from the Orange dataset has been converted from a factor to a numeric.

data(Orange);
Orange$NTree=as.numeric(as.character(Orange$Tree))
knitr::kable(
  head(Orange), 
  caption = "Data frame of Orange with transformed data in the NTree column"
)
Data frame of Orange with transformed data in the NTree column
Tree age circumference NTree
1 118 30 1
1 484 58 1
1 664 87 1
1 1004 115 1
1 1231 120 1
1 1372 142 1
  • Option one
par(mfrow=c(1,1))
nt=Orange$NTree[c(1:2,8:10,18:20,22:25,31:34)]
par(mfrow=c(1,1))
RadChart(nt,"Matura MT Script Capitals","black","firebrick",Vec="NTree")
## [1] "Plotting"

  • Option one
par(mfrow=c(1,1))
Age=Orange$circumference[1:7]
par(mfrow=c(1,1))
RadChart(Age,"Rockwell Extra Bold","black","red",Vec="Circumference")
## [1] "Plotting"

  • Option two
par(mfrow=c(2,2))
RadChart(Orange[1:8,2:4],"Eras Demi ITC","black","forestgreen")
## [1] "Plotting"

  • Option three
par(mfrow=c(1,1))
RadChart(Orange[c(1:2,5:7,9:11),2:4],"Jokerman","black",MV="Orange Dataset")
## [1] "Plotting"

Dataset Iris. It is the Edgar Anderson’s Iris Data

data(iris)
iris$ASepal=iris$Sepal.Length*iris$Sepal.Width
iris$APetal=iris$Petal.Length*iris$Petal.Width
knitr::kable(
  head(iris), 
  caption = "Iris dataset with calculated areas"
)
Iris dataset with calculated areas
Sepal.Length Sepal.Width Petal.Length Petal.Width Species ASepal APetal
5.1 3.5 1.4 0.2 setosa 17.85 0.28
4.9 3.0 1.4 0.2 setosa 14.70 0.28
4.7 3.2 1.3 0.2 setosa 15.04 0.26
4.6 3.1 1.5 0.2 setosa 14.26 0.30
5.0 3.6 1.4 0.2 setosa 18.00 0.28
5.4 3.9 1.7 0.4 setosa 21.06 0.68

Sample function was used to get a vector for this dataset using a set of 10 values from Sepal.Width

  • Option one
width=sample(iris$Sepal.Width,10)
par(mfrow=c(1,1))
RadChart(width,"Garamond","deepskyblue3","darkgreen",Vec="width")
## [1] "Plotting"

  • Option two
par(mfrow=c(2,2))
RadChart(iris[1:10,1:4],"Book Antiqua","blue4","darkgoldenrod")
## [1] "Plotting"

  • Option three
par(mfrow=c(1,1))
colnames(iris)=c("LSepal","WSepal","LPetal","WPetal","Species","ASepal","APetal")
RadChart(iris[7:10,c(1:4,6:7)],"Pristina","blue4",MV="Iris Dataset")
## [1] "Plotting"

Dataset mtcars

As the rownames in this dataset can be too long to represent axis labels, they were abbreviated with the function abbreviate.

data(mtcars);
rownames(mtcars)=abbreviate(rownames(mtcars))
knitr::kable(
head(mtcars), 
  caption = "Mtcars dataset"
)
Mtcars dataset
mpg cyl disp hp drat wt qsec vs am gear carb
MRX4 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4
MRXW 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4
D710 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1
Hr4D 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1
HrnS 18.7 8 360 175 3.15 3.440 17.02 0 0 3 2
Vlnt 18.1 6 225 105 2.76 3.460 20.22 1 0 3 1
HorsePower=mtcars$hp[7:24]
  • Option one
par(mfrow=c(1,1))
RadChart(HorsePower,"Javanese Text","black","indianred4",Vec="Horse Power")
## [1] "Plotting"

  • Option two
par(mfrow=c(2,2))
RadChart(mtcars[1:8,8:11],"High Tower Text","black","brown")
## [1] "Plotting"

  • Option three
par(mfrow=c(1,1))
RadChart(mtcars[c(1,8,15),1:6],"Bodoni MT Condensed","red",MV="Mtcars Dataset")
## [1] "Plotting"

I hope this function saves you time. Thank you for reading and have a great day (or night).