I am trying to crate two pie charts side by side using tikz. I’ve found a code in the web that I am adapting, and so far, it seems to work. However, instead of using a separate legend below, I would like to insert the series labels close to the figures % in the charts. Would someone knows how can I modify the code below in order to achieve it?
Thanks in advance for any help with that.
documentclass[twoside,a4paper,12pt]{report}
usepackage{tikz}
usetikzlibrary{chains,positioning,shapes.symbols}
%define each color I want to use for each country/slice
definecolor{Australia} {RGB} {47,117,181}
definecolor{Brazil} {RGB} {0,176,80}
definecolor{Canada} {RGB} {244,176,132}
definecolor{China} {RGB} {191,143,0}
definecolor{France} {RGB} {155,194,230}
definecolor{Germany} {RGB} {198,89,17}
definecolor{Greece} {RGB} {221,235,247}
definecolor{Guinea} {RGB} {255,0,255}
definecolor{Guyana} {RGB} {255,217,102}
definecolor{Hungary} {RGB} {198,224,180}
definecolor{India} {RGB} {248,203,173}
definecolor{Indonesia} {RGB} {146,208,80}
definecolor{Ireland} {RGB} {255,217,0}
definecolor{Jamaica} {RGB} {131,60,12}
definecolor{Japan} {RGB} {31,78,120}
definecolor{Middle East} {RGB} {84,130,53}
definecolor{Norway} {RGB} {255,255,0}
definecolor{Russia} {RGB} {255,0,0}
definecolor{Suriname} {RGB} {112,48,160}
definecolor{UK} {RGB} {204,51,0}
definecolor{USA} {RGB} {0,0,255}
definecolor{USSR} {RGB} {255,0,0}
definecolor{Others} {RGB} {166,166,166}
tikzstyle{chart}=[legend label/.style={font={scriptsize},anchor=west,align=left},
legend box/.style={rectangle, draw, minimum size=5pt},
axis/.style={black,semithick,->},
axis label/.style={anchor=east,font={tiny}},]
tikzstyle{pie chart}=[chart,
slice/.style={line cap=round, line join=round, very thick,draw=white},
pie title/.style={font={bf}},
slice type/.style 2 args={
##1/.style={fill=##2},
values of ##1/.style={}}]
pgfdeclarelayer{background}
pgfdeclarelayer{foreground}
pgfsetlayers{background,main,foreground}
newcommand{pie}[3][]{
begin{scope}[#1]
pgfmathsetmacro{curA}{90}
pgfmathsetmacro{r}{1}
defc{(0,0)}
node[pie title] at (90:1.5) {#2};
foreach v/s in{#3}{
pgfmathsetmacro{deltaA}{v/100*360}
pgfmathsetmacro{nextA}{curA + deltaA}
pgfmathsetmacro{midA}{(curA+nextA)/2}
path[slice,s] c
-- +(curA:r)
arc (curA:nextA:r)
-- cycle;
pgfmathsetmacro{d}{max((deltaA * -(.5/50) + 1) , .5)}
begin{pgfonlayer}{foreground}
path c -- node[pos=d,pie values,values of s]{$v%$} +(midA:r);
end{pgfonlayer}
globalletcurAnextA
}
end{scope}}
newcommand{legend}[2][]{
begin{scope}[#1]
path
foreach n/s in {#2}
{
++(0,-10pt) node[s,legend box] {} +(5pt,0) node[legend label] {n}
}
;
end{scope}
}
begin{document}
begin{figure}
centering
begin{tikzpicture}
[ pie chart,
slice type={Australia}{Australia},
slice type={Brazil}{Brazil},
slice type={Canada}{Canada},
slice type={China}{China},
slice type={France}{France},
slice type={Germany}{Germany},
slice type={Greece}{Greece},
slice type={Guinea}{Guinea},
slice type={Guyana}{Guyana},
slice type={Hungary}{Hungary},
slice type={India}{India},
slice type={Indonesia}{Indonesia},
slice type={Ireland}{Ireland},
slice type={Jamaica}{Jamaica},
slice type={Japan}{Japan},
slice type={Middle East}{Middle East},
slice type={Norway}{Norway},
slice type={Russia}{Russia},
slice type={Suriname}{Suriname},
slice type={UK}{UK},
slice type={USA}{USA},
slice type={USSR}{USSR},
slice type={Others}{Others},
pie values/.style={font={small}},
scale=2
]
pie[xshift=0cm,values of Australia/.style={pos=1.2},values of Jamaica/.style={pos=1.2},values of Suriname/.style={pos=1.2},values of USSR/.style={pos=1.2},values of France/.style={pos=1.2},values of Greece/.style={pos=1.2},values of Guinea/.style={pos=1.2},values of Guyana/.style={pos=1.2},values of Hungary/.style={pos=1.2},,values of Others/.style={pos=1.2}]%
{1972}{20/Australia,18/Jamaica,10/Suriname,11/USSR,5/France,3/Greece,4/Guinea,5/Guyana,3/Hungary,21/Others}
pie[xshift=4cm,values of Australia/.style={pos=1.2},values of Brazil/.style={pos=1.2},values of China/.style={pos=1.2},values of Indonesia/.style={pos=1.2},,values of Guinea/.style={pos=1.2},values of India/.style={pos=1.2},values of Jamaica/.style={pos=1.2},values of Russia/.style={pos=1.2},values of Others/.style={pos=1.2}]%
{2010}{32/Australia,15/Brazil,14/China,11/Indonesia,8/Guinea,6/India,4/Jamaica,3/Russia,7/Others}
legend[shift={(-2cm,-1.5cm)}]{{Australia}/Australia,{Brazil}/Brazil,{China}/China}
legend[shift={(-0.5cm,-1.5cm)}]{{France}/France,{Greece}/Greece,{Guinea}/Guinea}
legend[shift={(1cm,-1.5cm)}]{{Guyana}/Guyana,{Hungary}/Hungary,{India}/India}
legend[shift={(2.5cm,-1.5cm)}]{{Indonesia}/Indonesia,{Jamaica}/Jamaica,{Russia}/Russia}
legend[shift={(4cm,-1.5cm)}]{{Suriname}/Suriname,{USSR}/USSR,{Others}/Others}
end{tikzpicture}
end{figure}
end{document}