Preparing Data for `radarchart`

The radarchart package expects data to be in a format whereby each row corresponds to an axis on the chart (or a Label) and each column is a set of scores. An example is the built in data set, skills.

library(radarchart)
skills

In many cases your data will have a column for each axis, and each row is a set of observations. In the skills example we might build up a spreadsheet where each row is a person and each column a skill.

skillsByName

In order to use this data set with radarchart we need to rotate it. This can be done with packages such as tidyr.

library(tidyr)
skillsByLabel <- gather(skillsByName, key=Label, value=Score, -Name) %>%
                   spread(key=Name, value=Score)
skillsByLabel

If you don't want to have a dependency on tidyr then you can do the same thing using a few lines of base R code.

skillsByLabel <- as.data.frame(t(skillsByName[,-1]))
names(skillsByLabel) <- skillsByName$Name
skillsByLabel <- cbind(Label=row.names(skillsByLabel), skillsByLabel)
row.names(skillsByLabel) <- NULL

This rotated data set is now ready for use with radarchart.

chartJSRadar(scores = skillsByLabel, maxScale = 10)


Try the radarchart package in your browser

Any scripts or data that you put into this service are public.

radarchart documentation built on May 1, 2019, 10:52 p.m.