Radar chart/Spider chart

Overview

There is no dedicated chart type but with formulas and Cross sampling you can create one with Category Scatter chart.

How to create a Radar chart?

  1. Prepare series - one of the methods would be to use  PercentRank(series1, series1) formulas:
    PercentRank() returns the rank of a value in a series as a percentage (0..100) of the values in the series, e.g.,PercentRank(sek, sek) calculates the percentile value of the series 'sek' for each observation.
  2. Prepare position's values - in next Formula analysis use these four formulas for each series (note that some elements should be changed, see below for more information):
    • fx:s1*Sin((0)*2*pi()/6)
    • fx:s1*Cos((0)*2*pi()/6)
    • 100*Sin((0)*2*pi()/6)
    • 100*Cos((0)*2*pi()/6)
      Changing elements:
      - Each set of formulas should have successive number after Cos/Sin e.g., fx:s1*Cos((1)*2*pi()/6), fx:s1*Cos((2)*2*pi()/6).
      - The number at the end (here '6') is total number of series in initial data set.
      - We also recommend to rename these series as 'series1 X'; 'series1 Y', 'series1 X Max'; 'series1 Y Max'.
      NOTE: If you want to flip the chart by 90 degrees set Cos-series as first (X-series), and Sin-series as second (Y-series).
    • and add these at the end of list:
      • 0
      • 1
  3. Add Cross sampling with four 'Calculations: Last'.
    • Name three of them as 25th %-ile, 50th %-ile, 75th %-ile - these will be needed for intermediate lines. The fourth is your outer shape, the 100%-ile Max-series.
    • To avoid clutter, in Output mode > Label generation select the best option for your data set.
    • In Group panel create columns for X-series, Y-series, X Max-series, Y Max-series. Same series should be at first and last position (without this duplication the shape will not be closed).
    • Select '0' and add press 'Add selected series as new single series column', same for '1'.
    • We recommend to rename all columns to X, Y, X Max, Y Max, 0, and 1.
  4. Add Arithmetic analysis to prepare radar's intermediate lines.
    • Whole '25th %-ile' list multiply by 0.25
    • Whole '50th %-ile' list multiply by 0.5
    • Whole '75th %-ile' list multiply by 0.75
  5. Add Category Scatter chart.
    • Open Graph layout (Ctrl+L), leave/create pairs for:
      • Last X, Y
      • Last, X Max, Y Max
      • 25th %-ile, X Max, Y Max
      • 50th %-ile, X Max, Y Max
      • 75th %-ile, X Max, Y Max
    • Additionally you can create pairs for:
      • 0-point - add two 'Last, 0' series
      • markers - add Bubble graph type and Last X; Last Y; Last 1 (or add them on a line's graph style).
  6. Graphic style
    • Turn off labels - due to how it is constructed there will always be one doubled label. Click on each line, under Presentation properties > Content un-check 'Show value labels'.
      Instead use Legend labels or Observation labels - see here how to add them. You can copy-paste them to other points.
    • To change each line's style click on it and go to Presentation properties > Appearance > Graph style: Custom, set Line width and style.
    • Scale adjusting:
      • under Presentation properties > Scale > Display range set for example -150/150,
      • under Presentation properties > Appearance > Tick position select 'None',
      • un-check Presentation properties > Appearance > Show labels to hide numbers.
    • To turn off borders go to Presentation properties > Border > Width, select 'None'.
    • To turn off grid line, click on one and un-check box under Presentation properties > Appearance > Show grid line.
  7. Chart size - to avoid stretching the chart use Chart view size.

Adding more lines

You can easily add more lines.

  1. Go to Cross sampling and add, for example, calculation 'Value at: -1y' (for values one year back).
  2. Go to chart, open Graph layout (Ctrl+L).
  3. Adjust series - leave just Line for 'Value at, -1y, X' and 'Value at, -1y, Y'.

Examples

Radar on 'A Countries'

We have chosen five countries and presented their current and 2000's Human Development Index position on a radar.

Spider Pigs

Here we showed latest data for agricultural production from New Zealand. You can also see how to flip the outer shape of radar.

Economic spider web

In this example we have calculated percentile ranks relative to historic data for eight different USA's indicators.

 

Radar chart

Macrobond R API is available for users with Data+ and Legacy license (the latter without searching and revision history functions). Examples were tested on Macrobond version 1.27, Macrobond API for R version 1.2-8 and R 4.3.0.

See two methods of constructing radar charts - with ggplot2 + ggradar and fsmb. Examples are presented on Innovation Input Sub-index from Global Innovation Index.

 

Radar chart version 1 created with ggplot2 and ggradar packages (click to enlarge). Jump to code with ggplot2 + ggradar package.

 

 

 


Radar chart version 2 with fmsb package (click to enlarge). Jump to code with fmsb package.

 

With ggplot2 + ggradar

library(MacrobondAPI)
library(tidyverse)
library(countrycode)
library(ggradar)

#First column is the name of the groups and each column represents a variable.
#All columns must have the same scale.
#If the values of your columns are not between 0 and 1 you will need to specify the minimum value with grid.min and the maximum value with grid.max.

#create list of series
list_of_series<-c("gii0828", "gii0974", "gii1266", "gii0682", "gii1120", #Nigeria
                  "gii0849", "gii0995", "gii1287", "gii0703", "gii1141", #South Africa
                  "gii0773", "gii0919", "gii1211", "gii0627", "gii1065") #Ethiopia

#create empty vectors
values<-NULL
region<-NULL

#get region
for (i in list_of_series){
  region<-append(region, getMetadataValues(getMetadata(FetchOneTimeSeries(i)), "Region"))
}
#change region ISO codes to names
region<-countrycode(as.vector(region), origin="iso2c", destination ="country.name")

#set description
description_labels<-c("Human Capital & Research", "Infrastructure", "Business \nSophistication", 
                      "Institutions", "Market \nSophistication")
descriptions<-rep(description_labels, 3) #create this for data frame

#get values 
for (i in list_of_series){
  values<-append(values, last(getValues(FetchOneTimeSeries(i))))
}

#prepare data frame
data <- data.frame(region, descriptions, values)
#change format of data from long to wide
data <- spread(data, descriptions, values)

#set colors
colors <- c("#58A291", "#F68D2E", "#CD545B")

#plot
ggradar(data, 
        values.radar = c(0, 40, 80), #0%, 50%, 100% of values
        axis.labels = c(description_labels), #description of each 'arm'
        grid.min=0,grid.mid=40, grid.max=80, #grid labels
        background.circle.colour = "white", #background settings
        axis.line.colour = "grey", #axis line's settings
        axis.label.size=4,
        gridline.min.colour = "grey", #gridlines' settings
        gridline.mid.colour = "grey",
        gridline.max.colour = "grey",
        grid.label.size=5,
        group.colours = colors, #chart's lines settings
        group.line.width= 1.2,
        group.point.size=5,
        legend.title="Global Innovation Index", #legend's settings
        legend.position = "top", 
        legend.text.size = 10)

With fmsb

library(MacrobondAPI)
library(tidyverse)
library(countrycode)
library(fmsb)

#create list of series
list_of_series<-c("gii0828", "gii0974", "gii1266", "gii0682", "gii1120", #Nigeria
                  "gii0849", "gii0995", "gii1287", "gii0703", "gii1141", #South Africa
                  "gii0773", "gii0919", "gii1211", "gii0627", "gii1065") #Ethiopia

#create empty vectors
values<-NULL
region<-NULL

#get region
for (i in list_of_series){
  region<-append(region, getMetadataValues(getMetadata(FetchOneTimeSeries(i)), "Region"))
}
#change ISO codes to names
region<-countrycode(as.vector(region), origin="iso2c", destination ="country.name")

#set description
description_labels<-c("Human Capital & Research", "Infrastructure", "Business \nSophistication", 
                      "Institutions", "Market \nSophistication")
descriptions<-rep(description_labels, 3) #create this for data frame

#get values 
for (i in list_of_series){
  values<-append(values, last(getValues(FetchOneTimeSeries(i))))
}

#Data frame must have first row representing the maximum values of the data and the second row the minimum values.
#prepare data frame
data <- data.frame(region, descriptions, values)
#prepare data frame for max and min values
max_min <- as.data.frame(rbind(rep(80, 5), rep(0, 5)))
rownames(max_min) <- c("max", "min")
colnames(max_min) <- description_labels
                      
#change format of data from long to wide
data <- spread(data, descriptions, values) %>%
  column_to_rownames(var="region") #move first column to row names
data <- rbind(max_min, data) #join two data frames

#set colors
colors <- c("#58A291", "#F68D2E", "#CD545B")

#plot (mark radar chart and legend to plot them together)
radarchart(data, 
           axistype=1, #gridlines' settings
           cglcol = "gray", 
           axislabcol="grey", 
           caxislabels=c(0,20, 40, 60, 80), 
           pcol = colors, #chart's lines settings
           plty = 1,
           plwd = 2,
           vlcex=0.8, #size of value labels
           title = "Global Innovation Index") 

legend(x=1.3, y=1, #legend's position
       legend = rownames(data[-c(1,2),]), #exclude names for max and min
       bty="n", #border around legend, n=none
       pt.cex=1.8, #width of sample colors
       pch = 20,
       col = colors)