다음 누적 막대 그래프를 그리는 데 도움이 필요합니다.

다음 누적 막대 그래프를 그리는 데 도움이 필요합니다.

다음 그림을 그리는 데 도움이 필요합니다. 누적 막대 그래프라고 부르는 것 같아요. 여기에 이미지 설명을 입력하세요

답변1

이러한 유형의 그래프는 패키지를 사용하여 쉽게 생성할 수 있습니다 pgfplots. 예를 보려면 아래를 참조하세요. 그래프 에 대한 자세한 내용은 ybar stacked77페이지를 참조하세요.pgfplots 매뉴얼.

ybar stacked또한 그래프를 그래프로 변환하는 것도 고려해야 합니다 xbar stacked(78페이지 참조).pgfplots 매뉴얼); 그것들은 파싱하기 더 쉬운 경향이 있습니다.

편집하다: 뻔뻔하게 적응했어요Jake의 매우 자세한 답변에게누적 ybar 플롯에서 좌표 근처의 중앙 노드막대에 값을 추가하려면 다음을 수행하십시오.

여기에 이미지 설명을 입력하세요

\documentclass{article}

\usepackage{pgfplots}

\pgfplotstableread{
1   15  12  03  24  16  19
2   15  12  03  24  16  19
3   15  12  03  24  16  19
4   15  12  03  24  16  19
5   15  12  03  24  16  19
6   15  12  03  24  16  19  
}\datatable

\makeatletter
\pgfplotsset{
    calculate offset/.code={
        \pgfkeys{/pgf/fpu=true,/pgf/fpu/output format=fixed}
        \pgfmathsetmacro\testmacro{%
            (\pgfplotspointmeta*10^\pgfplots@data@scale@trafo@EXPONENT@y)%
            /2*\pgfplots@y@veclength)%
        }
        \pgfkeys{/pgf/fpu=false}
        },
    nodes near coords vertically centered/.style={
        every node near coord/.append style={
            /pgfplots/calculate offset,
            yshift=-\testmacro
        },
        nodes near coords align=center
    }
}
\makeatother

\begin{document}
\begin{tikzpicture}
\begin{axis}[
    ybar stacked,%
    bar width=15pt,%
    legend style={%
        at={(0,0)},%
        anchor=west,%
        at={(axis description cs:1.05,+0.5)}},%
    reverse legend,%
    xtick={1,2,...,6},%
    xticklabels={1,2,3,4,5,6},%
    enlarge x limits=0.1,%
    enlarge y limits=false,%
    ymin=0,%
    ymax=100.01,%
    ytick={0,10,...,100},%
    yticklabels={0\%,10\%,20\%,30\%,40\%,50\%,60\%,70\%,80\%,90\%,100\%},%
    xlabel={\textbf{Company}},%
    ylabel={\textbf{\% Distribution of efforts}},%
    point meta=explicit,
    nodes near coords={\pgfmathprintnumber[fixed zerofill,precision=1]{\pgfplotspointmeta}
    },
    every node near coord/.style={%
        check for zero/.code={ %
            \pgfmathfloatifflags{\pgfplotspointmeta}{0}{%
                \pgfkeys{/tikz/coordinate}%
            }{}%
        },%
        check for zero,%
        fill=white,%
        fill opacity=0.75,%
        text opacity=1,%
        font=\scriptsize,%
        inner ysep=0.5pt,%
    },%
    nodes near coords vertically centered,%
]
\addplot table [y=1, meta=1] \datatable;
\addlegendentry{A}
\addplot table [y=2, meta=2] \datatable;
\addlegendentry{B}
\addplot table [y=3, meta=3] \datatable;
\addlegendentry{C}
\addplot table [y=4, meta=4] \datatable;
\addlegendentry{D}
\addplot table [y=5, meta=5] \datatable;
\addlegendentry{E}
\addplot table [y=6, meta=6] \datatable;
\addlegendentry{F}
\end{axis}
\end{tikzpicture}
\end{document}

관련 정보