Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have the following data

data = {{7.5, 12.45, 12.45, 12.75, 12.75, 12.25, 12.25, 12.53, 12.53},
{8.5, 12.22, 12.22, 12.23, 12.23, 13, 13, 12.54, 12.54}, 
{9.5, 11.58, 11.53, 12.75, 13.48, 12.39, 12.52, 12.17, 13.56}, 
{10.5, 11.76, 11.82, 12.97, 13.55, 12.15, 11.88, 13.07, 12.79}, 
{11.5, 11.18, 11.85, 13.27, 13.02, 12.32, 13, 12.72, 12.63}, 
{12.5, 11.04, 11.61, 13.70, 14.17, 12.77, 12.79, 12.13, 11.78}, 
{13.5, 11.64, 10.68, 13.52, 14.03, 13.14, 13.21, 11.64, 12.13}, 
{14.5, 12.04, 12.12, 13.23, 13.67, 12.58, 13.02, 11.26, 12.05}, 
{15.5, 14.10, 14, 11.65, 11.68, 12.17, 12.36, 12.19, 11.85}, 
{16.5, 14.85, 14.54, 10.94, 11.62, 12.17, 11.72, 11.84, 12.31}, 
{17.5, 15.78, 15.78, 10.62, 10.62, 11.72, 11.72, 11.88, 11.88}, 
{18.5, 17.18, 17.18, 9.53, 9.53, 11.66, 11.66, 11.63, 11.63}};

but I can't find a way to visualize them. Let me explain the structure of the data and also what I want to plot. data contains 12 sub-lists and each one contains 9 elements. The first element, let's say, is the x-coordinate and all the other eight represent percentages. I would like to plot these percentages with vertical lines (something like a histogram). So, at the axis there should be 7.5, 8.5, 9.5, ... , 18.5 and above of every number eight vertical lines (with different colors and indicators 1, 2, 3, ..., 8 if possible) of the corresponding percentages. Any ideas how to implement this?

EDIT

Following @Pinguin Dirk 's method I added some style options using

B0 = BarChart[Rest /@ data, Frame -> True, 
FrameTicks -> {{True, False}, {False, False}}, 
FrameLabel -> {"h", "Percentage %"}, 
FrameStyle -> Directive[FontSize -> 18, FontFamily -> "Helvetica"], 
ChartLabels -> {data[[All, 1]], None}, BarSpacing -> {1, 3}, 
ChartLegends -> Range[8], PlotRange -> {-1, 18}, ImageSize -> 550]

This is the output

enter image description here

Some minor issues:

(a). How can we manipulate the size/fonts of the numbers at the horizontal axis (7.5, 8.5, etc)?

(b). How can we manipulate the size/fonts of the chart's legends? Is there a way to increase the size of the squares or change the used colors?

share|improve this question
    
you want something like that: BarChart[Rest /@ data, ChartLabels -> {data[[All, 1]], None}]? –  Pinguin Dirk Oct 4 '13 at 7:09
    
@PinguinDirk Something like that but with a little white space between every eight bars. Anyway, post an answer if you like so to accept it. –  Vaggelis_Z Oct 4 '13 at 7:45
1  
Glad you like it! Posted - don't accept just yet, other users might have better ideas! Give them some time –  Pinguin Dirk Oct 4 '13 at 7:49

7 Answers 7

up vote 11 down vote accepted

As discussed in the comment, it seems you want:

BarChart[Rest /@ data, ChartLabels -> {data[[All, 1]], None}, 
   BarSpacing -> {0, 2}]

see other options in BarChart to format as you desire (as I do not know what it is for, it's hard to suggest other things), bonne chance!

enter image description here

or a version with labels for the bars, placed above the bars (see documentation of BarChart for more information):

BarChart[Rest /@ data, 
   ChartLabels -> {data[[All, 1]], Placed[Range[8], Above]}, 
   BarSpacing -> {0, 2}, ImageSize -> Large]

enter image description here

and here's edit numero 3, ChartLegends:

BarChart[Rest /@ data, ChartLabels -> {data[[All, 1]], None}, 
   BarSpacing -> {0, 2}, ChartLegends -> Range[8]]

enter image description here

and again, it's all there, see: BarChart

Based on your questions, here's the new version:

B0 = BarChart[Rest /@ data, Frame -> True, 
       FrameTicks -> {{True, False}, {False, False}}, 
       FrameLabel -> {"h", "Percentage %"}, 
       FrameStyle -> Directive[FontSize -> 18, FontFamily -> "Helvetica"], 
       ChartLabels -> {Style[#, FontSize -> 14] & /@ data[[All, 1]], None},
       BarSpacing -> {1, 3},
       ChartLegends -> 
            SwatchLegend[(Style[#, FontSize -> 24] & /@ Range[8]), 
               LegendMarkerSize -> Large],
       ChartStyle -> "GrayYellowTones",
       PlotRange -> {-1, 18}, ImageSize -> 550]

Note: the colors of the legend are based on the chart colors, I chose GrayYellowTones. For the font sizes, I just map a Style over the respective labels. Finally, to control the boxes sizes, I use SwatchLegend, see the respective info page for more info.

enter image description here

share|improve this answer
    
Is there a way to add labels to the bars? At the bottom or at the top of each bar? The labels should be 1, 2, 3 all the way to 8. –  Vaggelis_Z Oct 4 '13 at 8:11
    
added, I am sure you get the idea (and how to format the output as you desire it to be) - looks a bit crowded now... –  Pinguin Dirk Oct 4 '13 at 8:17
    
Yes, now its too crowded! Perhaps send the all the numbers in a table like PlotLegends? –  Vaggelis_Z Oct 4 '13 at 8:24
    
See my edit for some minor stylistic issues. –  Vaggelis_Z Oct 4 '13 at 9:15
    
@Vaggelis_Z, all addressed, see latest edit –  Pinguin Dirk Oct 4 '13 at 9:34

None of the solutions so far makes use of the fact that the data are percentages and hence add op to (nearly) 100.

(* Add the rows of the data list *)
Total[Rest /@ data, {2}]
(* out *)
{99.96, 99.98, 99.98, 99.99, 99.99, 99.99, 99.99, 99.97, 100., 99.99,100., 100.}

Borrowing from Pinguin Dirk:

BarChart[Rest /@ data
,ChartLayout -> "Stacked"
,ChartLabels -> {data[[All, 1]], None}
,ImageSize -> Large
]

enter image description here

share|improve this answer
    
good observation! PieChart[Rest /@ data], hypnotic! –  Pinguin Dirk Oct 4 '13 at 9:04
    
I believe this is spot on. But it will look better if, instead of a sequence of rectangles, each 'colored trend' was represented by a piecewise linear function (basically "connecting the dots"). It amounts to plotting the trends one in top of each other. –  Peltio Oct 4 '13 at 14:21
    
@Peltio: I guess it is hard to say if it is spot on, given the amount of details provided in the OP, for e.g. in this one here you cannot see temporal evolution of a single process clearly, as e.g. in the second bit of VLC's post (ListLinePlots). And this is not saying that mine's better (I was just trying to emulate what he was asking for directly) :) –  Pinguin Dirk Oct 4 '13 at 15:34
    
IMHO this approach gives a better view of the temporal evolution of single processes. The chosen approach is much harder to decipher. I am not talking here about implementation in mma, just that this sort of data make it difficult to follow single trends. The approach that I suggest with piecewise lines would make it easier to see when a determined process (color) is shrinking or expanding (and all in a single picture. As a matter of fact I've seen it used in many reports and in my humble opinion can be very effective. –  Peltio Oct 4 '13 at 17:45
    
Just to add, with the 'piecewise linear' approach: parallel lines -> process constant; convergent lines -> process shrinking; divergent lines -> process expanding. (I am probably abusing the term process here, but I believe it's clear what I mean). –  Peltio Oct 4 '13 at 17:54

One More way! The means of each data is the blue dot. bars are color coded according to the standard deviation within each sub list.

ListLinePlot[Mean /@ data, 
 Prolog -> 
  MapThread[{Thickness[.04], ColorData["SandyTerrain"][#3], 
     Line[{{#2, First@#1}, {#2, Last@#1}}], Opacity[0.7], White, 
     Dashed, Thickness[0.003], Arrowheads[0.025], 
     Arrow[{{#2, First@#1}, {#2, Last@#1}}]} &, {{Min@#, Max@#} & /@ 
     data, Range[Length@data], Normalize[StandardDeviation /@ data]}],
  PlotLegends -> 
  Placed[BarLegend[{"SandyTerrain", {Min@#, 
        Max@#} &@(StandardDeviation /@ data)}, 
    StandardDeviation /@ data, LegendMarkerSize -> 310, 
    LegendFunction -> (Framed[#, RoundingRadius -> 3] &), 
    LegendLabel -> Style["Stan. Dev.", Gray, FontSize -> 14]], {After,
     Top}],
 PlotRange -> {{0.5, 1 + Max[Length@data]}, {0.9 Min@data, 
    1.05 Max@data}},
 PlotStyle -> Red,
 MeshStyle -> {{Opacity[.7], Blue, PointSize[0.015]}},
 Frame -> True, Mesh -> All, ImageSize -> 600 , Axes -> None, 
 FrameStyle -> Directive[FontSize -> 14], 
 FrameLabel -> {"i-th data", "min to max arrow"}]

enter image description here

share|improve this answer
    
Visually I like this better than the crowded barchart! +1 –  cormullion Oct 4 '13 at 11:42
    
@cormullion Thx! But this thing fails if Length@data is too big. We need to do some other tricks then with Line thickness may be... –  PlatoManiac Oct 4 '13 at 11:47

Out of curiosity I tried this:

DistributionChart[Rest /@ data,
 ChartLabels -> {data[[All, 1]]},
 ChartElementFunction -> "HistogramDensity",
  ChartStyle -> {LightRed, LightGreen, LightBlue},
 BarOrigin -> Left]

chart

As for 'interpretation', here's my attempt.

This type of chart tries to show the distribution of the values in each 'row'. The height of each box is the number of elements that are considered to be 'grouped'. It might be easier to understand using some of the other options. For example:

DistributionChart[Rest /@ data, ChartLabels -> {data[[All, 1]]}, 
 ChartStyle -> {Directive[
    EdgeForm[None]], {Directive[Darker@Cyan]}}, 
 ChartElementFunction -> 
  ChartElementData["PointDensity", PointSize -> 9], BarOrigin -> Bottom, 
 ImageSize -> 550]

With the "PointDensity" option, you can see that it's trying to show the changing distribution by varying the color intensity of the background, with the data points plotted (very small) in black. Perhaps the effect is too subtle to be generally useful...

a point density

As with most Mathematica functions, there's enough flexibility built-in to allow any amount of specialized graphical treatments:

f[{{xmin_, xmax_}, {ymin_, ymax_}}, metadata___] :=
 { Opacity[1],
  Gray,
  Line[{{(xmin + xmax)/2, ymin}, {(xmin + xmax)/2, ymax}}], 
  Opacity[0.25],
  Darker@Green,
  EdgeForm[],
  Disk[{(xmin + xmax)/2, #}, .15] & /@ metadata
  }
DistributionChart[Rest /@ data,
 ChartLabels -> {data[[All, 1]]},
 ChartElementFunction -> f, 
 BarOrigin -> Bottom,
 ImageSize -> 550]

special chart function

share|improve this answer
1  
I am sure this is exactly what he had in mind :) +1! –  Pinguin Dirk Oct 4 '13 at 8:19
    
Nice plot but I cannot interpret it! What do we see here?! –  Vaggelis_Z Oct 4 '13 at 8:23
1  
@PinguinDirk :) One day I will find a use for SectorChart3D ... –  cormullion Oct 4 '13 at 8:23
    
@cormullion well done job here! I missed this point of view. +1 –  PlatoManiac Oct 5 '13 at 22:13

Since nobody has used this function yet, I will place it here. Your data seems to be organised almost perfectly for ArrayPlot. First I removed the first column from the rest of the values and added to the axes ticks. The rest is just displayed via ArrayPlot, with a particular color scale.

{xs, values} = {First[#], Transpose@Rest[#]} &@Thread@data;

ArrayPlot[values, Frame -> True, 
FrameTicks -> {{MapIndexed[{Last@#2, #1} &, xs], None}, {Table[i, {i, 1, 8}], None}}, 
ColorFunction -> "Temperature",PlotLegends -> Automatic]

*Edit: added the option PlotLegends which is now available in Mathematica 9

share|improve this answer
2  
what does this visualization show? how do i read it? –  im so confused Oct 4 '13 at 14:02
    
@im so confused you can just use the option "PlotLegends->Automatic" –  lalmei Oct 5 '13 at 11:31

A solution for PieChart aficionados:

GraphicsGrid[Partition[
  Table[PieChart[(Rest /@ data)[[i]], 
  ChartLabels -> Placed[Range[8], "RadialOutside"], 
  PlotLabel -> data[[i, 1]]], {i, Length[data[[All, 1]]]}], 4], 
  ImageSize -> 400]

enter image description here

Or, if you are interested in the temporal evolution of each process:

GraphicsGrid[Partition[
  Table[ListLinePlot[
  Transpose[{data[[All, 1]], Transpose[(Rest /@ data)][[i]]}], 
  PlotRange -> {{7, 19}, {0, 20}}, AxesOrigin -> {7, 0}, 
  PlotLabel -> i], {i, Length[(Rest /@ data)[[1]]]}], 4], 
  ImageSize -> 600]

enter image description here

If you want to adjust fonts and their sizes:

GraphicsGrid[Partition[
  Table[PieChart[(Rest /@ data)[[i]], 
  ChartLabels -> 
  Placed[Range[8], "RadialOutside", 
  Style[#, FontFamily -> "Helvetica", 12] &], 
  PlotLabel -> 
  Style[data[[i, 1]], FontFamily -> "Helvetica", 14, Bold]], {i, 
  Length[data[[All, 1]]]}], 4], ImageSize -> 400]

GraphicsGrid[Partition[
  Table[ListLinePlot[
  Transpose[{data[[All, 1]], Transpose[(Rest /@ data)][[i]]}], 
  LabelStyle -> (Directive[FontFamily -> "Helvetica", 12]), 
  PlotRange -> {{7, 19}, {0, 20}}, AxesOrigin -> {7, 0}, 
  PlotLabel -> Style[i, 14, Bold]], {i, 
  Length[(Rest /@ data)[[1]]]}], 4], ImageSize -> 600]
share|improve this answer
    
Nice approach! Any ideas how to manipulate size/fonts of the Plot and Chart labels? –  Vaggelis_Z Oct 4 '13 at 10:07
    
@Vaggelis_Z See update. –  VLC Oct 4 '13 at 12:18

Is this helpful?

Grid[Partition[BarChart /@ (Transpose[Thread[{#1, ##2}] & /@ data]), 
  4]]

enter image description here

You could standardize the plot range.

share|improve this answer

Your Answer

 
discard

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.