Creating Interactive Radar Charts in R with the ‘fmsb’ Library

[This article was first published on Steve's Data Tips and Tricks, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Introduction

Radar charts, also known as spider, web, polar, or star plots, are a useful way to visualize multivariate data. In R, we can create radar charts using the fmsb library. Here are several examples of how to create radar charts in R using the fmsb library:

Examples

Example 1: Basic radar chart

The following code creates a basic radar chart using the radarchart() function from the fmsb package. The input data format is specific, where each row represents an entity and each column is a variable. The first row should be the maximum values of the data, and the second row should be the minimum values. The default radar chart can be customized using various options, such as line color, fill color, line width, and axis label color.

# Load the fmsb package
library(fmsb)

# Create sample data
data <- as.data.frame(matrix(sample(2:20, 10, replace = T), 
                             ncol = 10))
colnames(data) <- c("Var1", "Var2", "Var3", "Var4", "Var5", 
                    "Var6", "Var7", "Var8", "Var9", "Var10")
data <- rbind(rep(20, 10), rep(0, 10), data)

# Create a basic radar chart
radarchart(data)

Example 2: Customized radar chart

The following code creates a customized radar chart using the radarchart() function. The axistype argument is set to 1 to customize the polygon, and the pcol, pfcol, and plwd arguments are used to customize the grid and line properties.

# Create sample data
data <- as.data.frame(matrix(sample(2:20, 10, replace = T), 
                             ncol = 10))
colnames(data) <- c("Var1", "Var2", "Var3", "Var4", "Var5", 
                    "Var6", "Var7", "Var8", "Var9", "Var10")
data <- rbind(rep(20, 10), rep(0, 10), data)

# Customize the radar chart
radarchart(data, axistype = 1, pcol = rgb(0.2, 0.5, 0.5, 0.9), 
           pfcol = rgb(0.2, 0.5, 0.5, 0.5), plwd = 4, cglcol =
          "grey", cglty = 1)

Example 3: Radar chart with multiple groups

The following code creates a radar chart with multiple groups using the radarchart() function. The input data frame should have more than three variables as axes, and the rows indicate cases as series. The first row should show the maximum values, the second row should show the minimum values, and the actual data should be given as row 3 and lower rows.

# Create sample data
set.seed(1)
data <- data.frame(rbind(rep(10, 8), rep(0, 8), 
                         matrix(sample(0:10, 24, replace = TRUE),
                                nrow = 3)))
colnames(data) <- paste("Var", 1:8)

# Create a radar chart with multiple groups
radarchart(data, axistype = 1, pcol = 1, plwd = 2, 
           pdensity = 10, pangle = 40, cglty = 1, 
           cglcol = "gray")

Conclusion

These are just a few examples of how to create radar charts in R using the fmsb library. With some creativity, you can customize the charts to suit your needs. I encourage you to try creating your own radar charts using the fmsb library and experiment with different options to see what works best for your data.

References:

  • [1] https://www.datanovia.com/en/blog/beautiful-radar-chart-in-r-using-fmsb-and-ggplot-packages/
  • [2] https://r-graph-gallery.com/142-basic-radar-chart.html
  • [3] https://www.geeksforgeeks.org/how-to-create-radar-charts-in-r/
  • [4] https://r-charts.com/ranking/radar-chart/
  • [5] https://www.statology.org/radar-chart-in-r/
  • [6] https://rdrr.io/cran/fmsb/man/radarchart.html
To leave a comment for the author, please follow the link and comment on their blog: Steve's Data Tips and Tricks.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)