Radar-like diagram

Drawing a radar-like diagram. Text can be added with the function putText; the legend is written next to the data sector.

Radar-like diagram

\documentclass[border=10pt]{standalone}
\usepackage[inline]{asymptote}
\begin{asydef}
struct RadarPlot{

  real[] data;
  string[] Legend;
  pen[] Pens;
  pen gridPen;
  pen axisPen;
  pen labelPen;
  pen legendPen;
  int n,m;
  real pieAngle;
  int maxX;
  int maxY;
  real step;
  real Step;
  pair O=(0,0);

  void drawSectors(){
    guide g;
    for(int i=0;i270){
        label(t*Legend[i],v,unit(v),legendPen);
      }else{
        label(rotate(a-180)*Legend[i],v,unit(v),legendPen);        
      }

    }
  }

  void draw(){
    drawGrid();
    drawSectors();
    drawAxes();
    drawLabels();
    drawLegend();
  }  

  void putText(string s, real x, real y, pair pos=O, pen p=currentpen){
    label(s,rotate(x*pieAngle)*(y,0),pos,p);
  }

  void operator init(real[] data, string[] Legend, pen[] Pens
    ,int maxX=2data.length
    ,int maxY=(int)max(data)+1
    ,pen gridPen=rgb(0.812,0.8,0.776)
    ,pen axisPen=darkblue
    ,pen labelPen=deepblue
    ,pen legendPen=deepgreen
    ,real step=1
    ,real Step=2step
  ){
    this.data=copy(data);
    this.Pens=copy(Pens);
    this.Legend=copy(Legend);

    this.n=data.length;
    this.m=Pens.length;
    this.pieAngle=360/n;
    this.maxX=maxX;
    this.maxY=maxY;
    this.gridPen=gridPen;
    this.axisPen=axisPen;
    this.labelPen=labelPen;
    this.legendPen=legendPen;
    this.step=step;
    this.Step=Step;
  }

};
\end{asydef}
\usepackage{lmodern}
\begin{document}
\begin{asy}
settings.outformat="pdf";
size(300);
texpreamble("\renewcommand{\familydefault}{\sfdefault}");
real[] data={
5,5,4,5,5,4,4,5,6,5,5,4,};

pen op=opacity(0.8);

pen[] Pens={
op+rgb(0,0.91,0.769),
op+rgb(0.298,0.835,0.549),
op+rgb(0.365,0.906,0.408),
op+rgb(0.973,0.965,0.333),
op+rgb(1,0.812,0.298),
op+rgb(1,0.463,0.302),
op+rgb(1,0.318,0.447),
op+rgb(1,0.322,0.749),
op+rgb(0.875,0.337,0.91),
op+rgb(0.702,0.349,0.914),
op+rgb(0.294,0.482,0.922),
op+rgb(0,0.804,0.929),
};


string[] Legend={
"set A","set B","set C","set D","set E","set F","set G",
"set H","set I","set J","set K","set L",};

RadarPlot rp=RadarPlot(data,Legend,Pens,maxY=9,Step=3);

rp.draw();
rp.putText("Test A",4.5,10);
rp.putText("Test B",9  , 8,W);

\end{asy}
\end{document}

Source: TeX.SE

Author: g.kov (License)