Legenda e legenda do gráfico aranha

Legenda e legenda do gráfico aranha

Gostaria de acrescentar: legenda (vermelho, azul e verde) e legenda da figura (com legenda) para meu gráfico Keviat. O código do meu keviat está listado abaixo. Obrigado

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

\begin{document}
\begin{tikzpicture}[label distance=.15cm,rotate=30,scale=0.75]

\tkzKiviatDiagram[radial=3,lattice=7,gap=1,step=1,label space=2]%
    {Cover,
    Droppings,
    Other,
    }
\tkzKiviatLine[thick,color=red,fill=red,label=SiteA](0.78,5.59,2.02);label{p4}
    \tkzKiviatLine[thick,color=blue,fill=blue](5.92,1.57,3.06);label{p5}
    \tkzKiviatLine[thick,color=green,fill=green](2.9,4.6,3.6);label{p6}
    \tkzKiviatGrad[suffix=\%,unity=10](0)
\end{tikzpicture}


\end{document}   

Responder1

Aqui está uma possibilidade. Se quiser que seu objeto seja tratado como um objeto flutuante, você pode usar o figureambiente e depois o comando padrão \captionpara fornecer a legenda (como fiz no meu primeiro código de exemplo). Se você não quiser que seu diagrama flutue, você pode usar um minipageambiente e o \captionofcomando integrado às classes KOMA-Script, para fornecer a legenda (como fiz no meu segundo código de exemplo).

Para desenhar a legenda, você pode usar a \nodee a tabular, na posição desejada; é claro que você pode alterar as configurações de acordo com suas necessidades.

Primeiro, tratando o diagrama como um figureobjeto flutuante:

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

\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}

\newcommand\ColorBox[1]{\textcolor{#1}{\rule{2ex}{2ex}}}

\begin{document}

\begin{figure}
\centering
\begin{tikzpicture}[label distance=.15cm,rotate=30,scale=0.75]

\tkzKiviatDiagram[radial=3,lattice=7,gap=1,step=1,label space=2]%
    {Cover,
    Droppings,
    Other,
    }
\tkzKiviatLine[thick,color=red,fill=red,label=SiteA](0.78,5.59,2.02);label{p4}
    \tkzKiviatLine[thick,color=blue,fill=blue](5.92,1.57,3.06);label{p5}
    \tkzKiviatLine[thick,color=green,fill=green](2.9,4.6,3.6);label{p6}
    \tkzKiviatGrad[suffix=\%,unity=10](0)
\node[anchor=south west,xshift=-60pt,yshift=40pt] at (current bounding box.south east) 
{
\begin{tabular}{@{}lp{3cm}@{}}
\ColorBox{red!50} & red description \\
\ColorBox{green!50} & green description \\
\ColorBox{blue!50} & blue description \\
\end{tabular}
};
\end{tikzpicture}
\caption{A caption for the diagram}
\label{fig:test}
\end{figure}

\end{document} 

insira a descrição da imagem aqui

E sem flutuação:

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

\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}

\newcommand\ColorBox[1]{\textcolor{#1}{\rule{2ex}{2ex}}}

\begin{document}

\noindent\begin{minipage}{\linewidth}
\centering
\begin{tikzpicture}[label distance=.15cm,rotate=30,scale=0.75]

\tkzKiviatDiagram[radial=3,lattice=7,gap=1,step=1,label space=2]%
    {Cover,
    Droppings,
    Other,
    }
\tkzKiviatLine[thick,color=red,fill=red,label=SiteA](0.78,5.59,2.02);label{p4}
    \tkzKiviatLine[thick,color=blue,fill=blue](5.92,1.57,3.06);label{p5}
    \tkzKiviatLine[thick,color=green,fill=green](2.9,4.6,3.6);label{p6}
    \tkzKiviatGrad[suffix=\%,unity=10](0)
\node at (current bounding box.east) 
{
\begin{tabular}{@{}ll@{}}
\ColorBox{red} & red description \\
\ColorBox{green} & green description \\
\ColorBox{blue} & blue description \\
\end{tabular}
};
\end{tikzpicture}
\captionof{figure}{A caption for the diagram}
\label{fig:test}
\end{minipage}

\end{document}

Nas classes padrão book, report, article, o \captionofcomando é acessível através de um dos pacotescapt-ofoucaption.

Responder2

Com PSTricks.

insira a descrição da imagem aqui

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-node}
\usepackage{multido}

\makeatletter
\def\LoadVerbs{\pstVerb{/pt2cm {\strip@pt\psunit\space div} bind def}}
\makeatother

\psset{opacity=0.5,fillstyle=solid}     

\def\Atom#1%
{
    \multido{\i=1+1}{#1}{\psline[linecolor=gray](\i,0)(0,\i)}
    \psline{->}(!#1 12 pt2cm add 0)
}

\def\Molecule#1%
{
    \multido{\i=0+90}{4}{\rput{\i}(0,0){\Atom{#1}}}
    \multido{\ix=1+1,\i=10+10}{#1}{\rput*{*0}(!\ix\space 6 pt2cm sub -10 pt2cm){\i\%}}
    \foreach \a/\t in {0/Right,90/Top,180/Left,270/Bottom}{\pnode(!#1 42 pt2cm add \a\space PtoC){\t}}
}

\def\Label(#1,#2)#3%
{
    \psframe[linecolor=#3,fillcolor=#3](#1,#2)(!#1 12 pt2cm add #2 12 pt2cm add)
    \rput[l](!#1 18 pt2cm add #2 6 pt2cm add){#3 description}
}

\addtopsstyle{gridstyle}{griddots=0}
\begin{document}
\begin{pspicture}[showgrid=false](-8,-8)(9,8)
\LoadVerbs
\rput{30}(0,0)
{
    \Molecule{7}
    \pspolygon[linecolor=red,fillcolor=red](0.75,0)(0,6.75)(-2,0)
    \pspolygon[linecolor=green,fillcolor=green](3,0)(0,4.75)(-3.75,0)
    \pspolygon[linecolor=blue,fillcolor=blue](6,0)(0,1.75)(-3,0)
    \foreach \n/\t in {Right/Cover,Top/Droppings,Left/Other}{\rput{*0}(\n){\t}}%! removing white space
}
\foreach \y/\c in {-3/red,-4/green,-5/blue}{\Label(5,\y){\c}}
\end{pspicture}
\end{document}

Como é feito?

insira a descrição da imagem aqui

\documentclass{beamer}
\usepackage{pst-node}
\usepackage{multido}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{pspicture}
\PreviewBorder=12pt

\makeatletter
\def\LoadVerbs{\pstVerb{/pt2cm {\strip@pt\psunit\space div} bind def}}
\makeatother

\psset{opacity=0.5,fillstyle=solid}     

\def\Atom#1%
{
    \multido{\i=1+1}{#1}{\psline[linecolor=gray](\i,0)(0,\i)}
    \psline{->}(!#1 12 pt2cm add 0)
}

\def\Molecule#1%
{
    \multido{\i=0+90}{4}{\only<+->{\rput{\i}(0,0){\Atom{#1}}}}
    \only<+->{\multido{\ix=1+1,\i=10+10}{#1}{\rput*{*0}(!\ix\space 6 pt2cm sub -10 pt2cm){\i}}}%!
    \foreach \a/\t in {0/Right,90/Top,180/Left,270/Bottom}{\pnode(!#1 42 pt2cm add \a\space PtoC){\t}}%!
}

\def\Label(#1,#2)#3%
{
    \psframe[linecolor=#3,fillcolor=#3](#1,#2)(!#1 12 pt2cm add #2 12 pt2cm add)
    \rput[l](!#1 18 pt2cm add #2 6 pt2cm add){#3 description}
}

\addtopsstyle{gridstyle}{griddots=0}
\begin{document}
\begin{frame}
\begin{pspicture}[showgrid=false](-8,-8)(9,8)
\LoadVerbs
\rput{30}(0,0)
{
    \Molecule{7}%!
    \only<+->{\pspolygon[linecolor=red,fillcolor=red](0.75,0)(0,6.75)(-2,0)}%!
    \only<+->{\pspolygon[linecolor=green,fillcolor=green](3,0)(0,4.75)(-3.75,0)}%!
    \only<+->{\pspolygon[linecolor=blue,fillcolor=blue](6,0)(0,1.75)(-3,0)}%!
    \foreach \n/\t in {Right/Cover,Top/Droppings,Left/Other}{\only<+->{\rput{*0}(\n){\t}}}%! removing white space
}
\foreach \y/\c in {-3/red,-4/green,-5/blue}{\only<+->{\Label(5,\y){\c}}}
\end{pspicture}
\end{frame}
\end{document}

Responder3

O método mais simples com tikz:

Primeiro defini um ponto (LegendBox_anchor), que é uma âncora para a caixa da legenda. Então usei uma linha para mostrar a cor usada para uma linha tkzKiviatDiagram. As diferentes linhas são colocadas com (LegendBox_anchor). A descrição é um simples nó adicionado no final da linha. anchor=westé usado para alinhar corretamente as descrições

\coordinate[xshift=-2cm] (LegendBox_anchor) at (current bounding box.south east) ;
\draw[line width=3mm,color=red] (LegendBox_anchor) -- ++(.5,0) node[anchor=west] {red description};
\draw[line width=3mm,color=blue] ([yshift=8mm]LegendBox_anchor) -- ++(.5,0) node[anchor=west] {blue description};
\draw[line width=3mm,color=green] ([yshift=16mm]LegendBox_anchor) -- ++(.5,0) node[anchor=west] {green description};

É possível, em vez de linhas, usar retângulos ou nós. Os nós têm várias vantagens para obter alguns refinamentos mas tentei criar algo fácil de usar.

Outra possibilidade é definir uma caixa ao redor da descrição diferente. Eu posso se você adicionar essa possibilidade mais tarde.

Agora talvez seja interessante adicionar uma macro ao pacote para obter legendas. Aqui eu adicionei uma macro simples (primeiro tente estender o pacote)

\newcommand{\LegendBox}[3][]{%
\coordinate[#1] (LegendBox_anchor) at (#2) ;
    \foreach \col/\item [count=\hi from 0] in {#3} {
    \draw[line width=3mm,color=\col] ([yshift=\hi*8mm]LegendBox_anchor) -- ++(.5,0) 
                                    node[anchor=west] {\item}
                                    ;}
}

É baseado nas primeiras linhas. O argumento nº 1 é usado para obter uma melhor posição da caixa de legenda, se necessário.

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

\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}

\newcommand{\LegendBox}[3][]{%
\coordinate[#1] (LegendBox_anchor) at (#2) ;
    \foreach \col/\item [count=\hi from 0] in {#3} {
    \draw[line width=3mm,color=\col] ([yshift=\hi*8mm]LegendBox_anchor) -- ++(.5,0) 
                                    node[anchor=west] {\item}
                                    ;}
}

\begin{document}

\begin{tikzpicture}[label distance=.15cm,scale=0.75]
\begin{scope}[rotate=30]
    \tkzKiviatDiagram[radial=3,lattice=7,gap=1,step=1,label space=2]%
        {Cover,
        Droppings,
        Other,}
        \tkzKiviatLine[thick,color=red,fill=red,label=SiteA](0.78,5.59,2.02)
        \tkzKiviatLine[thick,color=blue,fill=blue](5.92,1.57,3.06)
        \tkzKiviatLine[thick,color=green,fill=green](2.9,4.6,3.6)
        \tkzKiviatGrad[suffix=\%,unity=10](0)
\end{scope}
\LegendBox[xshift=-2cm]{current bounding box.south east}%
          {red/red decription,
           blue/blue description,
           green/green }
\end{tikzpicture}
\end{document} 

insira a descrição da imagem aqui

observação: você não precisa adicionar ;no final de\tkzKiviatLine

Atualizar :

Adicionei uma caixa ao redor das legendas, removi algumas, ;usei nós em vez de linhas

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

\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}

\newcommand{\LegendBox}[3][]{%
\xdef\fitbox{}%
\coordinate[#1] (LegendBox_anchor) at (#2) ;
    \foreach \col/\item [count=\hi from 0] in {#3} {
       \node[color = \col,draw,
             fill  = \col!50,
             minimum width  = 4 ex,
             minimum height = 2 ex,
             label={[anchor = left,name=b\hi]right:\item}] at ([yshift=\hi*4 ex]LegendBox_anchor) {};
             \xdef\fitbox{\fitbox(b\hi)}
   }%
 \node [draw,fit=\fitbox(LegendBox_anchor)] {};
}

\begin{document}
\begin{tikzpicture}[label distance=.15cm,scale=0.75]
\begin{scope}[rotate=30]
    \tkzKiviatDiagram[radial=3,lattice=7,gap=1,step=1,label space=2]%
        {Cover,
        Droppings,
        Other}
        \tkzKiviatLine[thick,color=red,fill=red,label=SiteA](0.78,5.59,2.02)
        \tkzKiviatLine[thick,color=blue,fill=blue](5.92,1.57,3.06)
        \tkzKiviatLine[thick,color=green,fill=green](2.9,4.6,3.6)
        \tkzKiviatGrad[suffix=\%,unity=10](0)
\end{scope}
\LegendBox[shift={(-3cm,3cm)}]{current bounding box.south east}%
          {red/red decription,
           blue/blue description,
           green/green description }
\end{tikzpicture}
\end{document} 

insira a descrição da imagem aqui

informação relacionada