[Tex/LaTex] Kiviat diagram with axis labeled and different sizes

tikz-pgftkz-kiviat

I am trying to use the package tkz-kiviat to draw a kiviat. The following example produces the image below:

\documentclass[]{scrartcl}
\usepackage[utf8]{inputenc} 
\usepackage[T1]{fontenc}
\usepackage[upright]{fourier} 
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{tkz-kiviat,numprint,fullpage} 
\usetikzlibrary{arrows}
\thispagestyle{empty}

\begin{document} 
\begin{tikzpicture}
\tkzKiviatDiagram[scale=1.25,label distance=.5cm,
        radial  = 5,
        gap     = 1,  
        lattice = 5]{McCabe,LOC,Live Variables,Halstead N,Variablenspanne}
\tkzKiviatLine[thick,color=blue,mark=none,
               fill=blue!20,opacity=.5](3,3.5,3,3.5,3)
\tkzKiviatLine[thick,color=darkgray,
               fill=green!20,opacity=.5](0.5,1,0.5,0.75,1) 
\tkzKiviatLine[ultra thick,mark=ball,
                 mark size=4pt,color =Maroon](2,3.75,1,1.5,2)    
\tkzKiviatGrad[prefix=,unity=100,suffix=\ \texteuro](1)  
\end{tikzpicture}

\end{document}

Kiviat produced with the code above

My questions are:

  1. Is it possible to have axes with different sizes? In the previous example, all the axes go from 0 to 5. I would like to have one axis from 0 to 3, other from 0 to 2, and so on.
  2. Is it possible to label the axes with enumerated values? In the previous example, instead of having 100€, 200€, etc. I would like to have Axis1: Active, Passive. Axis2: Earth, Venus, Sun, …

Is this possible with this pacakge? Do I need to use another one?

Best Answer

An example for my alternate approach with TikZ nodes:

\documentclass[parskip]{scrartcl}
\usepackage[margin=15mm]{geometry}
\usepackage{tikz}
\usepackage{xifthen}
\usepackage{wasysym}

\newcommand{\myshape}{circle}
\newcommand{\myfillcolor}{white}
\newcommand{\mydrawcolor}{black}
\newcommand{\myfontcolor}{black}
\newcommand{\mynodecontent}{black}

\newcommand{\multiscale}[2]{% mode, planet
\ifthenelse{\equal{#1}{passive}}{\renewcommand{\mydrawcolor}{green!70!blue}}{}
\ifthenelse{\equal{#1}{active}}{\renewcommand{\mydrawcolor}{red!80!yellow}}{}
% ---------
\ifthenelse{\equal{#2}{Mercury}}{\renewcommand{\myfillcolor}{black!75}\renewcommand{\mynodecontent}{\mercury}}{}
\ifthenelse{\equal{#2}{Venus}}{\renewcommand{\myfillcolor}{black!50}\renewcommand{\mynodecontent}{\venus}}{}
\ifthenelse{\equal{#2}{Earth}}{\renewcommand{\myfillcolor}{black!25}\renewcommand{\mynodecontent}{\earth}}{}
\node[color=-\mydrawcolor,draw=\mydrawcolor,fill=\myfillcolor,circle,ultra thick,minimum size=1cm] {\textbf{\mynodecontent}};
}

\begin{document}

\begin{tikzpicture}
\multiscale{passive}{Mercury}
\end{tikzpicture}
\begin{tikzpicture}
\multiscale{passive}{Venus}
\end{tikzpicture}
\begin{tikzpicture}
\multiscale{passive}{Earth}
\end{tikzpicture}

\begin{tikzpicture}
\multiscale{active}{Mercury}
\end{tikzpicture}
\begin{tikzpicture}
\multiscale{active}{Venus}
\end{tikzpicture}
\begin{tikzpicture}
\multiscale{active}{Earth}
\end{tikzpicture}


\end{document}

enter image description here

In this case, passive is green frame, active is red frame, and the planets become lighter gray outwards from the sun. Of course, you'd have to provide a nice key for explanation.


Edit 1: I've had a look at the documentation of tkz-kiviat and as far as I can see it is not possible. I made a little concept how it might work, but it need horribly much manual tweaking. Also, i have no idea about text labels as pgfmath can only extract numbers from array like structures. Probably you can also ask Altermundus, the author of tkz-kiviat and also a user on this site.

\documentclass[parskip]{scrartcl}
\usepackage[margin=15mm]{geometry}
\usepackage{tikz}

\newcommand{\kivaxisnumbers}{3}
\newcommand{\kivcategorycounts}{{2,3,4}}
\newcommand{\kivkumulativecategorycounts}{{0,2,5}}
\newcommand{\kivcategorynames}{{1,2,10,20,30,100,200,300,400}}
\newcommand{\kivlcmcatcount}{12}

\newcommand{\kivlattice}{%
\pgfmathsetmacro{\kivaxisangle}{360/\kivaxisnumbers}
    \foreach \x in {1,...,\kivaxisnumbers}
    {   \foreach \y in {1,...,\kivlcmcatcount}
        {   \pgfmathsetmacro{\kivaxisstep}{6/\kivlcmcatcount}
            \draw[help lines] (\kivaxisangle*\x:\y*\kivaxisstep) -- (\kivaxisangle*\x+\kivaxisangle:\y*\kivaxisstep);
        }
    }
    \foreach \x in {1,...,\kivaxisnumbers}
    {   \draw[->] (0,0) -- (\kivaxisangle*\x:6cm);
        \pgfmathsetmacro{\kivaxissteps}{\kivcategorycounts[\x-1]}
        \pgfmathsetmacro{\kivaxisstep}{6/\kivcategorycounts[\x-1]}
        \foreach \y in {1,...,\kivaxissteps}
        {   \pgfmathsetmacro{\kivhelper}{\kivkumulativecategorycounts[\x-1]}
            \pgfmathtruncatemacro{\kivlabelname}{\kivcategorynames[\kivhelper+\y-1]}
            \node[circle,fill=black,label=\x*\kivaxisangle+90:\kivlabelname,inner sep=1pt] at (\kivaxisangle*\x:\kivaxisstep*\y) {};
        }
    }

}

\begin{document}

\begin{tikzpicture}
\kivlattice
\end{tikzpicture}

\end{document}

enter image description here


Edit 2: For adding some data (in percentages of the axes):

\newcommand{\kivdatapoints}{}

\newcommand{\kivdata}[2]{% values in percentages of max, color
    \renewcommand{\kivdatapoints}{{#1}}
    \pgfmathsetmacro{\kivaxisangle}{360/\kivaxisnumbers}
    \pgfmathsetmacro{\kivcoordinate}{\kivdatapoints[0]*6}
    \fill[opacity=0.2,#2] (\kivaxisangle:\kivcoordinate) 
        \foreach \x in {1,...,\kivaxisnumbers}
        {   %\pgfmathsetmacro{\kivcoordinate}{\kivdatapoints[\x-1]*6}
            -- (\kivaxisangle*\x:\kivdatapoints[\x-1]*6) 
        }
    -- cycle;
}

\begin{document}

\begin{tikzpicture}
\kivlattice
\kivdata{0.2,0.9,0.6}{red}
\kivdata{0.7,0.1,0.8}{green}
\kivdata{0.4,0.35,0.3}{blue}
\end{tikzpicture}

enter image description here


Edit 3: Thanks to Brandon Kuczenski's answer in this question, I was able to add text labels to the axes:

\documentclass[parskip]{scrartcl}
\usepackage[margin=15mm]{geometry}
\usepackage{tikz}
\usepackage{arrayjobx}

\makeatletter
\usepackage{trimspaces}
\def\trimspace#1{\trim@spaces@in{#1}}
\makeatother

\newarray\kivaxisitemlabels
\readarray{kivaxisitemlabels}{%
Decision  & Yes    & No     &        &       &
Color     & Red    & Blue   & Yellow &       &
Direction & North  & East   & South  & West  &
Taste     & Sour   & Salty  & Bitter & Sweet &
World     & Normal & Nether & End    &       }
\dataheight=5

\newcommand{\kivcurrentlabel}[2]{\checkkivaxisitemlabels(#1,#2)\trimspace\cachedata \cachedata}

\newcommand{\kivaxisnumbers}{5}
\newcommand{\kivcategorycounts}{{2,3,4,4,3}}
\newcommand{\kivkumulativecategorycounts}{{0,2,5,9,13}}
%\newcommand{\kivcategorynames}{{1,2,10,20,30,100,200,300,400}}
\newcommand{\kivlcmcatcount}{12}

\newcommand{\kivlattice}{%
\pgfmathsetmacro{\kivaxisangle}{360/\kivaxisnumbers}
    \foreach \x in {1,...,\kivaxisnumbers}
    {   \foreach \y in {1,...,\kivlcmcatcount}
        {   \pgfmathsetmacro{\kivaxisstep}{6/\kivlcmcatcount}
            \draw[help lines] (\kivaxisangle*\x:\y*\kivaxisstep) -- (\kivaxisangle*\x+\kivaxisangle:\y*\kivaxisstep);
        }
    }
    \foreach \x in {1,...,\kivaxisnumbers}
    {   \draw[->] (0,0) -- (\kivaxisangle*\x:6cm);
        \pgfmathsetmacro{\kivaxissteps}{\kivcategorycounts[\x-1]}
        \pgfmathsetmacro{\kivaxisstep}{6/\kivcategorycounts[\x-1]}
        \foreach \y in {1,...,\kivaxissteps}
        {   %\pgfmathsetmacro{\kivhelper}{\kivkumulativecategorycounts[\x-1]}
            %\pgfmathtruncatemacro{\kivlabelname}{\kivcategorynames[\kivhelper+\y-1]}
            %\node[circle,fill=black,label=\x*\kivaxisangle+90:\kivlabelname,inner sep=1pt] at (\kivaxisangle*\x:\kivaxisstep*\y) {};
            \pgfmathtruncatemacro{\kivlabelnumber}{\y+1}            
            \node[circle,fill=black,label=\x*\kivaxisangle+90:\kivcurrentlabel{\x}{\kivlabelnumber},inner sep=1pt] at (\kivaxisangle*\x:\kivaxisstep*\y) {};
        }
    }
}

\newcommand{\kivdatapoints}{}

\newcommand{\kivdata}[2]{% values in percentages of max, color
    \renewcommand{\kivdatapoints}{{#1}}
    \pgfmathsetmacro{\kivaxisangle}{360/\kivaxisnumbers}
    \pgfmathsetmacro{\kivcoordinate}{\kivdatapoints[0]*6}
    \fill[opacity=0.2,#2] (\kivaxisangle:\kivcoordinate) 
        \foreach \x in {1,...,\kivaxisnumbers}
        {   %\pgfmathsetmacro{\kivcoordinate}{\kivdatapoints[\x-1]*6}
            -- (\kivaxisangle*\x:\kivdatapoints[\x-1]*6) 
        }
    -- cycle;
}

\begin{document}

\begin{tikzpicture}
\kivlattice
\kivdata{0.2,0.9,0.6,0.5,0.5}{red}
\kivdata{0.7,0.1,0.8,0.6,.2}{green}
\kivdata{0.4,0.35,0.3,0.25,0.2}{blue}
\end{tikzpicture}

\end{document}

enter image description here

Related Question