Friday, February 14, 2014

Menggambar Diagram Lingkaran

Pada materi Statistika kita menemukan ini. Bagaimana cara menggambar diagram lingkaran dengan $\small\LaTeX$?

Salah satu pilihan yang layak digunakan adalah paket pgf-pie. Paket yang berdasarkan pada paket grafis PGF/TikZ yang dirilis (v0.2) pada 2 Oktober 2011 ini dibuat oleh Yuan Xu.


Di bawah ini adalah contoh pengkodean dan dokumen tentang penggunaan paket pgf-pie. Dokumen tersebut saya tulis dengan menggunakan $\small\LaTeX$ melalui ShareLaTeX. Petunjuk penggunaan perintah-perintah dalam pgf-pie dapat Anda unduh di sini.

Demikian semoga bermanfaat!

Adjie Gumarang Pujakelana 2014


\documentclass{article}
\usepackage{pgf-pie}
\usepackage[indonesian]{babel}
\usepackage[scaled]{helvet}
\renewcommand*\familydefault{\sfdefault}
\title{\Huge\bfseries pgf-pie}
\usepackage[lmargin=2cm,rmargin=2cm,tmargin=1.5cm]{geometry}
\usepackage[tikz]{bclogo}
\usetikzlibrary{shadows}
\usepackage{calc}
\usepackage{fancyvrb}
\usepackage{graphicx}
\usepackage[dvipsnames]{xcolor}
   \definecolor{LightGray}{RGB}{193,193,193}
   \definecolor{LightYellow}{RGB}{253,247,172}

%%%%% \printmacro

\newcommand{\printmacro}[1][mc]{% mc = label of storange bin
%
{\setlength{\fboxrule}{3.0\fboxrule}% thickness of frame
\setlength{\fboxsep}{1.5\fboxsep}% separation between text and frame
%
\noindent%
\fcolorbox{LightGray}{LightYellow}{% frame and background color
%
\begin{minipage}[c]{1.08\linewidth - 2.0\fboxrule - 2.0\fboxsep}
\protect\UseVerbatim[fontsize=\footnotesize]{#1} % font size of text in verbatim
\end{minipage}}%
}%
}

%%%% \printmacroi

% \macroicon is used by \printmacroi to print the icon and some horizontal space
\newcommand{\macroicon}{%
\hspace{1em}%
\parbox[c]{0.75cm}{\includegraphics[keepaspectratio=true,width=0.75cm]{light-bulb-icon}}%
\hspace{1em}%
}

% \newmacroicon provides a quicker way to renew \macroicon mid-document
\newcommand{\newmacroicon}[3][1em]{%
\renewcommand{\macroicon}{%
\hspace{#1}%
\parbox[c]{#2}{\includegraphics[keepaspectratio=true,width=#2]{#3}}%
\hspace{#1}%
}}

\newlength\macroiconwidth

\newcommand{\printmacroi}[1][mc]{%
%
{\setlength{\fboxrule}{3.0\fboxrule}%
\setlength{\fboxsep}{1.5\fboxsep}%
%
\noindent%
\fcolorbox{LightGray}{LightYellow}{%
%
\macroicon%
\settowidth{\macroiconwidth}{\macroicon}%
%
\begin{minipage}[c]{\linewidth - \macroiconwidth - 2.0\fboxrule - 2.0\fboxsep}
\protect\UseVerbatim[fontsize=\footnotesize]{#1}
\end{minipage}}%
}%
}
  
  
\author{\color{blue!40!orange} Adjie Gumarang Pujakelana}
\date{\today}

\begin{document}

\maketitle

\begin{bclogo}[logo=\bclampe, couleurBarre=white, noborder=false]{Awali dengan Pie}
\begin{minipage}[c]{0.5\textwidth}
\begin{SaveVerbatim}{mc}
\begin{tikzpicture}
\pie{10/Jagung, 20/Kedelai, 30/Padi, 40/Kacang tanah}
\end{tikzpicture}
\end{SaveVerbatim}
\printmacro
\end{minipage}\hfill
%
\begin{minipage}[c]{0.5\textwidth}
\begin{tikzpicture}
    \pie{10/Jagung, 20/Kedelai, 30/Padi, 40/Kacang tanah}
    \end{tikzpicture}
\end{minipage}\hfill
\end{bclogo}

\bigskip
\begin{bclogo}[logo=\bclampe, couleurBarre=white, noborder=false]{Posisi, Pemutaran, dan Ukuran}
\begin{minipage}[c]{0.5\textwidth}
\begin{SaveVerbatim}{mc}
\begin{tikzpicture}
\pie{10/, 20/, 30/, 40/}%
\pie[pos={6,0},rotate=180,radius=2.5]{10/, 20/, 30/, 40/}%
\pie[pos={11,0},radius=2]{10/, 20/, 30/, 40/}%
\end{tikzpicture}
\end{SaveVerbatim}
\printmacro
\end{minipage}\hfill

\begin{minipage}[c]{0.5\textwidth}
\begin{tikzpicture}
\pie{10/, 20/, 30/, 40/}%
\pie[pos={6,0},rotate=180,radius=2.5]{10/, 20/, 30/, 40/}%
\pie[pos={11,0},radius=2]{10/, 20/, 30/, 40/}%
\end{tikzpicture}
\end{minipage}\hfill
\end{bclogo}

\begin{bclogo}[logo=\bclampe, couleurBarre=white, noborder=false]{Pewarnaan}
\begin{minipage}[c]{0.5\textwidth}
\begin{SaveVerbatim}{mc}
\begin{tikzpicture}
\pie[color={black!10, black!20,black!30,black!40}]
{10/A, 20/B, 30/C, 40/ D}
\pie[pos={8,0}, color=blue!20] {10/A, 20/B, 30/C, 40/ D}
\end{tikzpicture}
\end{SaveVerbatim}
\printmacro
\end{minipage}\hfill

\begin{minipage}[c]{0.5\textwidth}
\begin{tikzpicture}
    \pie[color={black!10, black!20,black!30,black!40}]{10/A, 20/B, 30/C, 40/ D}
    \pie[pos={9,0}, color=blue!20] {10/A, 20/B, 30/C, 40/ D}
\end{tikzpicture}
\end{minipage}\hfill
\end{bclogo}

\bigskip
\begin{bclogo}[logo=\bclampe, couleurBarre=white, noborder=false]{Perenggangan}
\begin{minipage}[c]{0.5\textwidth}
\begin{SaveVerbatim}{mc}
\begin{tikzpicture}
% perenggangan tertentu
\pie[explode={0, 0, 0, 0.1}]{10/A, 20/B, 30/C, 40/D}
% perenggangan semua
\pie[pos={8,0}, explode=0.1]{10/A, 20/B, 30/C, 40/D}
\end{tikzpicture}
\end{SaveVerbatim}
\printmacro
\end{minipage}\hfill

\begin{minipage}[c]{0.5\textwidth}
\begin{tikzpicture}
% perenggangan tertentu
\pie[explode={0, 0, 0, 0.1}]{10/A, 20/B, 30/C, 40/D}
% perenggangan semua
\pie[pos={9,0}, explode=0.1]{10/A, 20/B, 30/C, 40/D}
\end{tikzpicture}
\end{minipage}\hfill
\end{bclogo}

\begin{bclogo}[logo=\bclampe, couleurBarre=white, noborder=false]{Sudut Irisan (\emph{Slice})}
\begin{minipage}[c]{0.5\textwidth}
\begin{SaveVerbatim}{mc}
\begin{tikzpicture}
\pie[sum=auto, after number=, radius=3]{33/Pria, 7/Wanita}
\pie[pos={9,0}, sum=40, after number=, radius=3]{33/Pria}
\end{tikzpicture}
\end{SaveVerbatim}
\printmacro
\end{minipage}\hfill

\begin{minipage}[c]{0.5\textwidth}
\begin{tikzpicture}
\pie[sum=auto, after number=, radius=3]{33/Pria, 7/Wanita }
\pie[pos={9,0}, sum=40, after number=, radius=3]{33/Pria }
\end{tikzpicture}
\end{minipage}\hfill
\end{bclogo}

\bigskip
\begin{bclogo}[logo=\bclampe, couleurBarre=white, noborder=false]{Teks dan Angka}
\begin{minipage}[c]{0.5\textwidth}
\begin{SaveVerbatim}{mc}
\begin{tikzpicture}
\pie[before number={Rp}, after number=rb,]{10/A, 20/B, 
30/C, 40/D}
\pie[pos={9,0}, scale font]{10/A, 20/B, 30/C, 40/D}
\end{tikzpicture}
\end{SaveVerbatim}
\printmacro
\end{minipage}\hfill

\begin{minipage}[c]{0.5\textwidth}
\begin{tikzpicture}
\pie[before number={Rp}, after number=rb,]{10/A, 20/B, 30/C, 40/D}
\pie[pos={9,0}, scale font]{10/A, 20/B, 30/C, 40/D}
\end{tikzpicture}
\end{minipage}\hfill
\end{bclogo}

\begin{bclogo}[logo=\bclampe, couleurBarre=white, noborder=false]{Teks dan Penamaan}
\begin{minipage}[c]{0.5\textwidth}
\begin{SaveVerbatim}{mc}
\begin{tikzpicture}
\pie[text=pin]{10/A, 20/B, 30/C, 40/ D}
\pie[pos={9,0}, text=inside]{10/A, 20/B, 30/C, 40/D}
\end{tikzpicture}
\end{SaveVerbatim}
\printmacro
\end{minipage}\hfill

\begin{minipage}[c]{0.5\textwidth}
\begin{tikzpicture}
\pie[text=pin]{10/A, 20/B, 30/C, 40/ D}
\pie[pos={9,0}, text=inside]{10/A, 20/B, 30/C, 40/D}
\end{tikzpicture}
\end{minipage}\hfill
\end{bclogo}

\bigskip
\begin{bclogo}[logo=\bclampe, couleurBarre=white, noborder=false]{Teks dan Legenda}
\begin{minipage}[c]{0.5\textwidth}
\begin{SaveVerbatim}{mc}
\begin{tikzpicture}
\pie[text=legend]{10/Satu, 20/Dua, 30/Tiga, 40/Empat}
\end{tikzpicture}
\end{SaveVerbatim}
\printmacro
\end{minipage}\hfill

\begin{minipage}[c]{0.5\textwidth}
\begin{tikzpicture}
\pie[text=legend]{10/Satu, 20/Dua, 30/Tiga, 40/Empat}
\end{tikzpicture}
\end{minipage}\hfill
\end{bclogo}

\begin{bclogo}[logo=\bclampe, couleurBarre=white, noborder=false]{Bayangan (\emph{Shadow})}
\begin{minipage}[c]{0.5\textwidth}
\begin{SaveVerbatim}{mc}
\begin{tikzpicture}
% dengan \usetikzlibrary{shadows}
\pie[style=drop shadow]{10/A, 20/B, 30/C, 40/D}
\end{tikzpicture}
\end{SaveVerbatim}
\printmacro
\end{minipage}\hfill

\begin{minipage}[c]{0.5\textwidth}
\begin{tikzpicture}
% dengan \usetikzlibrary{shadows}
\pie[style=drop shadow]{10/A, 20/B, 30/C, 40/D}
\end{tikzpicture}
\end{minipage}\hfill
\end{bclogo}

\bigskip
\begin{bclogo}[logo=\bclampe, couleurBarre=white, noborder=false]{Diagram Berbentuk Kutub (\emph{Polar})}
\begin{minipage}[c]{0.5\textwidth}
\begin{SaveVerbatim}{mc}
\begin{tikzpicture}
\pie[style=drop shadow]{10/A, 20/B, 30/C, 40/D}
\end{tikzpicture}
\end{SaveVerbatim}
\printmacro
\end{minipage}\hfill

\begin{minipage}[c]{0.5\textwidth}
\begin{tikzpicture}
\pie[polar]{10/A, 20/B, 30/C, 40/D}
\end{tikzpicture}
\end{minipage}\hfill
\end{bclogo}

\begin{bclogo}[logo=\bclampe, couleurBarre=white, noborder=false]{Diagram Berbentuk Persegi}
\begin{minipage}[c]{0.5\textwidth}
\begin{SaveVerbatim}{mc}
\begin{tikzpicture}
\pie[square]{10/A, 20/B, 30/C, 40/D}
\end{tikzpicture}
\end{SaveVerbatim}
\printmacro
\end{minipage}\hfill

\begin{minipage}[c]{0.5\textwidth}
\begin{tikzpicture}
\pie[square]{10/A, 20/B, 30/C, 40/D}
\end{tikzpicture}
\end{minipage}\hfill
\end{bclogo}

\bigskip
\begin{bclogo}[logo=\bclampe, couleurBarre=white, noborder=false]{Diagram Berbentuk Awan}
\begin{minipage}[c]{0.5\textwidth}
\begin{SaveVerbatim}{mc}
\begin{tikzpicture}
\pie[cloud, text=inside, scale font]{10/A, 20/B, 30/C, 40/D}
\end{tikzpicture}
\end{SaveVerbatim}
\printmacro
\end{minipage}\hfill

\begin{minipage}[c]{0.5\textwidth}
\begin{tikzpicture}
\pie[cloud, text=inside, scale font]{10/A, 20/B, 30/C, 40/D}
\end{tikzpicture}
\end{minipage}\hfill
\end{bclogo}





\end{document}



-->

7 comments:

Apriyanti Arifin said...

terima kasih banyak pak adjie atas bimbingannya ...

Eman Sulaeman said...

Sama-sama, Bu.

Loechas Soemarno said...

Setelah membuang option : dvipsnames
pada
\usepackage[dvipsnames]{xcolor}
baru jadi jika dicompile dengan texlive 2016.
Pada Sharelatex, jika tidak dibuang option tersebut file pdf memang jadi, tetapi masih bergincu pak Adjie.

Apriyanti Arifin said...

iya benar

Apriyanti Arifin said...

iya benar, saya beri tanda % untuk paket xcolor

Eman Sulaeman said...

Pak Lukas, tolong diperbaiki: letakkan paket xplor itu pada baris kedua (tepat setelah kelas dokumen).

Eman Sulaeman said...

Saltik, maksudnya paket xcolor.

Related Posts Plugin for WordPress, Blogger...