Is there a charts package for LaTeX?
Such thing can easily be made with TikZ:
\documentclass{standalone}
\usepackage{tikz}
\tikzset{
mystyle/.style={inner sep=0pt, inner ysep = .5mm, anchor=west, text height=2mm},
mynum/.style={inner sep=0pt, inner ysep = .5mm, anchor=east}
}
\begin{document}
\newcommand{\myrow}[4]{%
#1 & \begin{tikzpicture}[baseline=-2pt]\node at (0,0)[ fill = red, text width=#2 cm,mystyle] {}; \node[mynum] at (1cm,0){\pgfmathparse{int(round(#2*100))}\pgfmathresult}; \end{tikzpicture}& %
\begin{tikzpicture}[baseline=-2pt]\node at (0,0)[ fill = blue, text width=#3 cm,mystyle] {}; \node[mynum] at (1cm,0){\pgfmathparse{int(round(#3*100))}\pgfmathresult}; \end{tikzpicture}&%
\begin{tikzpicture}[baseline=-2pt]\node at (0,0)[ fill = green, text width=#4 cm,mystyle] {}; \node[mynum] at (1cm,0){\pgfmathparse{int(round(#4*100))}\pgfmathresult}; \end{tikzpicture}\\
}
\begin{tabular}{lp{1cm}p{1cm}p{1cm}}
\myrow{yes}{1}{.5}{.75}
\myrow{no}{.33}{.2}{.9}
\myrow{maybe}{.02}{.2}{.9}
\end{tabular}
\end{document}
There is on thing I have to say about your picture: I as a reviewer would reject that thing. Why? Well look at the scale. It's a rubber scale. That means your projection point changes from cell to cell. Such cells can't be compared and the reader will get a false impression; e.g. 66 % and 52% look exactly the same. Now take a look at the result of mine: 100 % is always 1cm. This means (except small values) the projection is always the same.
Here is my solution, always based on TikZ.
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{backgrounds,shadings}
\newcommand{\barwidth}{2}
\newcommand{\barheight}{0.5}
\newcommand{\thescale}{100}
\newcommand{\setscale}[1]{\renewcommand{\thescale}{#1}}
\newcommand{\shadebar}[2][]{
\node[rectangle,minimum width=\barwidth cm,minimum height=\barheight cm,](a){};
\node[left] at(a.east){\ensuremath{#2\%}};
\ifnum#2=0
\def\shadebarwidth{0.01/\barwidth}
\else
\def\shadebarwidth{(#2/\thescale)*\barwidth}
\fi
\begin{pgfonlayer}{background}
\node[left color=#1,right color=white,draw=white,minimum width=\shadebarwidth cm,minimum height=\barheight cm,right]at (a.west){};
\end{pgfonlayer}
}
\begin{document}
\setscale{20}
\noindent
\tikz{\shadebar[green]{16}}\\
\tikz{\shadebar[red]{10}}\\
\setscale{100}
\tikz{\shadebar[blue]{60}}\\
\tikz{\shadebar[green]{100}}
\vspace{5cm}
\begin{tabular}{lp{\barwidth cm}p{\barwidth cm}p{\barwidth cm}}
Probing for ownership &\setscale{20}\tikz[baseline=-0.5ex]{\shadebar[blue]{16}} &\setscale{70}\tikz[baseline=-0.5ex]{\shadebar[blue]{69}} & \setscale{55}\tikz[baseline=-0.5ex]{\shadebar[green]{52}}\\
Summit &\setscale{20}\tikz[baseline=-0.5ex]{\shadebar[blue]{1}} &\setscale{70}\tikz[baseline=-0.5ex]{\shadebar[blue]{2}} & \setscale{55}\tikz[baseline=-0.5ex]{\shadebar[green]{50}}\\
Probing for expertise &\setscale{20}\tikz[baseline=-0.5ex]{\shadebar[blue]{17}} &\setscale{70}\tikz[baseline=-0.5ex]{\shadebar[blue]{34}} & \setscale{55}\tikz[baseline=-0.5ex]{\shadebar[green]{49}}\\
\end{tabular}
\end{document}
Basically, it allows you to define bars in which you can customize the width, the color and the scale. This because, you may wonder to change scale factor for your charts.
INTRODUCING LABELS
To introduce labels instead of simply numbers here is a solution:
\newcommand{\labeledshadebar}[3][]{
\node[rectangle,minimum width=\barwidth cm,minimum height=\barheight cm,](a){};
\node[left] at(a.east){#3};
\ifnum#2=0
\def\shadebarwidth{0.01/\barwidth}
\else
\def\shadebarwidth{(#2/\thescale)*\barwidth}
\fi
\begin{pgfonlayer}{background}
\node[left color=#1,right color=white,draw=white,minimum width=\shadebarwidth cm,minimum height=\barheight cm,right]at (a.west){};
\end{pgfonlayer}
}
The new command should be used as:
\tikz{\labeledshadebar[green]{16}{yes}}For example, changing the `document` content into:
\begin{document}
\setscale{20}
\noindent
\tikz{\shadebar[green]{16}}\\
\tikz{\labeledshadebar[green]{16}{yes}}\\
\tikz{\shadebar[red]{10}}\\
\setscale{100}
\tikz{\shadebar[blue]{60}}\\
\tikz{\labeledshadebar[blue]{60}{no}}\\
\tikz{\shadebar[green]{100}}
\vspace{2cm}
\begin{tabular}{lp{\barwidth cm}p{\barwidth cm}p{\barwidth cm}}
Probing for ownership &\setscale{20}\tikz[baseline=-0.5ex]{\shadebar[blue]{16}} &\setscale{70}\tikz[baseline=-0.5ex]{\shadebar[blue]{69}} & \setscale{55}\tikz[baseline=-0.5ex]{\shadebar[green]{52}}\\
Summit &\setscale{20}\tikz[baseline=-0.5ex]{\shadebar[blue]{1}} &\setscale{70}\tikz[baseline=-0.5ex]{\shadebar[blue]{2}} & \setscale{55}\tikz[baseline=-0.5ex]{\shadebar[green]{50}}\\
Probing for expertise &\setscale{20}\tikz[baseline=-0.5ex]{\shadebar[blue]{17}} &\setscale{70}\tikz[baseline=-0.5ex]{\shadebar[blue]{34}} & \setscale{55}\tikz[baseline=-0.5ex]{\shadebar[green]{49}}\\
\end{tabular}
\end{document}
it is possible to get:
Xparse implementation
To make things easier and to have just one command, it is possible to redefine the above commands by means of an xparse
definition:
\NewDocumentCommand{\shadebar}{O{blue} m o}{%
\node[rectangle,minimum width=\barwidth cm,minimum height=\barheight cm,](a){};
\IfNoValueTF{#3}{%true
\node[left] at(a.east){\ensuremath{#2\%}};
}
{%false
\node[left] at(a.east){#3};
}
\ifnum#2=0
\def\shadebarwidth{0.01/\barwidth}
\else
\def\shadebarwidth{(#2/\thescale)*\barwidth}
\fi
\begin{pgfonlayer}{background}
\node[left color=#1,right color=white,draw=white,minimum width=\shadebarwidth cm,minimum height=\barheight cm,right]at (a.west){};
\end{pgfonlayer}
}
Now the last example with labels could be simplified; in order to allow the customization inside the document of the \barwidth
and the \barheight
, I inserted two dedicated commands \setbarwidth
and \setbarheight
.
\documentclass{article}
\usepackage{xparse}
\usepackage{tikz}
\usetikzlibrary{backgrounds,shadings}
\newcommand{\barwidth}{2}
\newcommand{\barheight}{0.5}
\newcommand{\thescale}{100}
% To allow customization inside the document
\newcommand{\setscale}[1]{\renewcommand{\thescale}{#1}}
\newcommand{\setbarwidth}[1]{\renewcommand{\barwidth}{#1}}
\newcommand{\setbarheight}[1]{\renewcommand{\barheight}{#1}}
\NewDocumentCommand{\shadebar}{O{blue} m o}{%
\node[rectangle,minimum width=\barwidth cm,minimum height=\barheight cm,](a){};
\IfNoValueTF{#3}{%true
\node[left] at(a.east){\ensuremath{#2\%}};
}
{%false
\node[left] at(a.east){#3};
}
\ifnum#2=0
\def\shadebarwidth{0.01/\barwidth}
\else
\def\shadebarwidth{(#2/\thescale)*\barwidth}
\fi
\begin{pgfonlayer}{background}
\node[left color=#1,right color=white,draw=white,minimum width=\shadebarwidth cm,minimum height=\barheight cm,right]at (a.west){};
\end{pgfonlayer}
}
\begin{document}
\setbarwidth{3}
\setbarheight{0.75}
\setscale{20}
\noindent
\tikz{\shadebar[green]{16}}\\
\tikz{\shadebar[orange]{16}[yes]}\\
\tikz{\shadebar[red]{10}}\\
\setbarwidth{3.5}
\setbarheight{1}
\setscale{100}
\tikz{\shadebar{60}[no]}\\
\tikz{\shadebar[violet]{60}{no}}\\
\tikz{\shadebar[green!80!black]{100}}
\vspace{2cm}
\setbarwidth{2}
\setbarheight{0.5}
\begin{tabular}{lp{\barwidth cm}p{\barwidth cm}p{\barwidth cm}}
Probing for ownership &\setscale{20}\tikz[baseline=-0.5ex]{\shadebar{16}} &\setscale{70}\tikz[baseline=-0.5ex]{\shadebar{69}} & \setscale{55}\tikz[baseline=-0.5ex]{\shadebar[green]{52}}\\
Summit &\setscale{20}\tikz[baseline=-0.5ex]{\shadebar{1}} &\setscale{70}\tikz[baseline=-0.5ex]{\shadebar{2}} & \setscale{55}\tikz[baseline=-0.5ex]{\shadebar[green]{50}}\\
Probing for expertise &\setscale{20}\tikz[baseline=-0.5ex]{\shadebar{17}} &\setscale{70}\tikz[baseline=-0.5ex]{\shadebar{34}} & \setscale{55}\tikz[baseline=-0.5ex]{\shadebar[green]{49}}\\
\end{tabular}
\end{document}
See spark, sparklines and sparkln.
EDIT: Just noticed you also asked for Excel solutions. For that see sparklinesforxl on sourceforce (also see sparlinesforxl main site) or use the sparkline functionality built into Excel 2010 .
EDIT 2: Here is an example of using sparklinesforxl in Excel. We used the hbar
function here. For example, if cell a1
holds a fraction that we wish to display in light blue then we put the formula =hbar(a1, 15128749)
into the cell where we want the bar to appear or to display it in light green use =hbar(a1, 9498256)
.
There is a color chart here which can be used to avoid color computations although in this example what I actually did was to start with RGB values of (144, 238, 144) for light green and (173, 216, 230) for light blue and use the formula R + 256 * G + 256^2 * B
to get the corresponding numeric values shown in the last paragraph for argument 2.
EDIT 3: And here is a sparklines
package example:
\documentclass{article}
\usepackage{colortbl}
\usepackage[table]{xcolor}
\usepackage{sparklines}
\begin{document}
\setlength{\sparklinethickness}{5pt}
\begin{center}
\begin{tabular}{lllllll}
& \multicolumn{2}{l}{\bfseries E} &
\multicolumn{2}{l}{\bfseries O} &
\multicolumn{2}{l}{\bfseries E/O} \\
\bfseries First Line &
16\% & \definecolor{sparklinecolor}{RGB}{173,216,230}
\begin{sparkline}{5} \spark 0.0 0.5 0.16 0.5 / \end{sparkline} &
30\% & \definecolor{sparklinecolor}{RGB}{173,216,230}
\begin{sparkline}{5} \spark 0.0 0.5 0.30 0.5 / \end{sparkline} &
53\% & \definecolor{sparklinecolor}{RGB}{144,238,144}
\begin{sparkline}{5} \spark 0.0 0.5 0.53 0.5 / \end{sparkline} \\
\bfseries Second Line &
10\% & \definecolor{sparklinecolor}{RGB}{173,216,230}
\begin{sparkline}{5} \spark 0.0 0.5 0.10 0.5 / \end{sparkline} &
20\% & \definecolor{sparklinecolor}{RGB}{173,216,230}
\begin{sparkline}{5} \spark 0.0 0.5 0.20 0.5 / \end{sparkline} &
50\% & \definecolor{sparklinecolor}{RGB}{144,238,144}
\begin{sparkline}{5} \spark 0.0 0.5 0.50 0.5 / \end{sparkline} \\
\end{tabular}
\end{center}
\end{document}