TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have about five thousand observations which I would like to plot in a graph. Since the range of values is wide (from 1 to 108,000, with 90% of the observation taking a value of 2, 99% of the observations taking a value between 1 and 6, and just one observation taking the max value of 108,000) I thought that the only way to represent them graphically would be with a volume graph--that is, 3D. The circumference of the sphere will range from 3.89 to 185.62 (then possibly--keeping the same ratio--0.08cm to 3.7cm) in the figure.

This is my data along with the circumference (in cm) of a sphere of volume equivalent to the value of Var1

enter image description here

EDIT: TikZ in drawing a circle requires as attribute the radius not the circumference as I wrongly thought. I correct the formula below accordingly.

Of course, the graph doesn't need to show clearly all the small values. What I would like to give is the idea of a big sphere floating in a sea of micro spheres. Something like this:

enter image description here

First let's define a script to get the radius from the volume of the sphere. The R script is:

radiusFromVolume <- function(volume){
  radius <- (volume/((4/3)*pi))^(1/3)
  radius <- radius/10
  radius <- round(radius, digits=2)

From the R script I will obtain a vector of radius values. Now, the hard part. On these values I would like to draw a sphere for each item in the vector and dispose them (randomly?) in my figure.

Thanks to this answer (by Tom Bombadil) I come out with this basic script which gives me two spheres of radius 0.06 and 2.96.




    \draw (0,0) circle (2.96cm);
    \shade[ball color=blue!10!white,opacity=0.70] (0,0) circle (3.7cm);
    \draw (3,0) circle (0.06cm);
    \shade[ball color=blue!10!white,opacity=0.70] (3,0) circle (0.08cm);


Moving from this script, in pseudocode what I am trying to get through is:

vector <- {volume values} % The values are actually ordered from bigger to smaller to avoid the small spheres to be covered by the biggest spheres
figure_box <- {(-4,-4),(4,4)}


for (item in vector) {

size <- item 
coordinates <- ( random(>-4 && <4) , random(>-4 && <4) )
\draw (coordinates) circle (size cm);
\shade[ball color=blue!10!white,opacity=0.70] (coordinates) circle (size cm);


Is it possible to obtain with TeX and tikz?


Why not to use a log/log scale? The problem with my data is that I have one big outlier. A log-log plot of my data will be something like this

enter image description here

or like this

enter image description here

Clearly my outlier--for being so far off the other values--doesn't even show (you can only tell it is there from the X scale). Also log scales are not that easily understood by the median viewer. (On the contrary, differences in ball volumes are much easier to see...)

share|improve this question
your question is confusing, I don't understand what you're trying to achieve. How the percentages 90% + 99% are supposed to add up to 100%? Could you please rephrase your question and if possible add a sketch of what you have in mind as the final plot? – juliohm Oct 30 '13 at 9:54
2 is between 1 and 6. I will add a sketch. – Francesco Oct 30 '13 at 10:02
I have to say, I don't think this kind of graph is a great idea: it's an effort for the reader to figure out exactly what it is supposed to show, and even then, I don't think the final picture would convey much more information than the phrase "a big sphere floating in a sea of microspheres." Have you considered a histogram with logarithmic scales on both axes? – Charles Staats Oct 30 '13 at 11:37
See my edit on log/log plot. – Francesco Oct 30 '13 at 22:04

Neither should you use a logarhitmic bar chart (you can choose the "base" to be e.g. 101 or 10-5, which would drastically alter how the "bars" look), nor should you use a continuous line, as you have discrete values (there's no data for 1.5). In my opinion a double logarhitmic scatter plot would be the best:





\pgfplotsset{grid style={very thin,gray!30}}

    [   scatter,
        scatter src=y,
        only marks,
      x tick label style={align=right,rotate=90},
      enlarge x limits=0.01,
      enlarge y limits=0.02,
      log ticks with fixed point,
        \addplot coordinates {(1,180) (2,5400) (3,240) (4,120) (5,40) (6,20) (108000,1)};




enter image description here

share|improve this answer
Very nice output! I would even compress the x axis further to have only even powers of ten but that's a matter of taste. Minor nitpick; double logarithm is often used for log(log(x)). – percusse Oct 31 '13 at 12:19
@percusse: Thanks. But log(log(x))? I've never seen that before. Do you have an example for that, or at least a field where that is used? – Tom Bombadil Oct 31 '13 at 12:22
A quick example here tex.stackexchange.com/questions/69032/… – percusse Oct 31 '13 at 12:59
up vote 0 down vote accepted

I ended up with this solution:


\usepackage{datatool, tikz}



 \DTLforeach*{radius}{\radius=ball_radius} {%
    \draw (\X,\Y) circle (\radius);
    \shade[ball color=green] (\X,\Y) circle (\radius);}  


With output:

enter image description here

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.