Search code examples
rplotlapplyradar-chart

R: How to change the arguments of each individual radarplot that are created all at once


I am creating five radar plots:

library(fmsb)

plottm <- data.frame(clust = 1:5, 
                 Off = c(3,4,2,2,3), 
                 D_Eff = c(5,3,1,3,1), 
                 turn = c(1,1,1,1,1), 
                 Opp_Off = c(5,3,1,5,1), 
                 Opp_Def = c(4,3,3,1,1))
par(mar=c(2,2,2,2))
layout(matrix(1:5, ncol = 5))
lapply(1:5, function(x){
  radarchart(rbind(rep(1,5), rep(5,5), plottm[x,-1]), pfcol = '328', pcol = 'black', title = 'TM', plwd = 3)
})

enter image description here

Currently each plot has the same arguments. I would like to find out how to change the arguments for each plot. I would like to be able to set the title, plot data color and the polygon color for each plot.

If possible I would also like to change the line width for whatever plot has the smallest average plot data. In this case it would be plot five.

The plot data for plot five is c(3,1,1,1,1), The mean is 1.4, which is the smallest.

Any help will be appreciated please let me know if further information is needed.


Solution

  • It seems that you are quite close. I have modified you code a bit:

    library(fmsb)
    
    plottm <- data.frame(clust = 1:5, 
                         Off = c(3,4,2,2,3), 
                         D_Eff = c(5,3,1,3,1), 
                         turn = c(1,1,1,1,1), 
                         Opp_Off = c(5,3,1,5,1), 
                         Opp_Def = c(4,3,3,1,1))
    par(mar=c(2,2,2,2))
    layout(matrix(1:5, ncol = 5))
    
    colours <- c("white", "blue", "orange", "red", "green")
    titles <- c("Tm1", "Tm2", "Tm3", "Tm4", "Tm5")
    widths <- c(1, 3, 5, 8, 10)
    myWidths <- widths[order(rowSums(plottm[, -1]), decreasing= T)]
    lapply(1:5, function(x){
      radarchart(rbind(rep(1,5), rep(5,5), 
                       plottm[x,-1]), 
                       pfcol = '328', pcol = colours[x], title = titles[x], plwd = myWidths[x])
    })
    

    Results is this: Individual attributes of each graph