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.

enter image description here

Dear all,

I've been trying to set prepare a grid with different charts for comparisons. The issue I have is that the first row of the grid has the legend distorted. The issue does not occur for subsequent rows. (see the elongated legend boxes?).

I defined a function to create a combination of two charts, then created a grid and exported it to pdf.

chartTrends[country_, percent_] := Module[
  {a, b},
  a = salesTrend[country, percent];
  b = Table[
    Labeled[Last[a][[i]], 
     If[Mod[i, 4] == 1, Rotate[headings[[i]], 90 Degree], None]], {i, 
     Range@Length@headings}];
  Grid[{{BarChart[b, ChartLayout -> "Percentile", 
      ChartStyle -> ColorData[35, "ColorList"], 
      PlotRegion -> {{0.10, 0.90}, {0.10, 0.90}}, ImageSize -> 1000, 
      ChartLegends -> 
       Placed[Style[#, FontSize -> Small] & /@ First[a], Right]], 
     BarChart[b, ChartStyle -> ColorData[35, "ColorList"], 
      PlotRegion -> {{0.10, 0.90}, {0.10, 0.90}}, 
      ChartLayout -> "Stacked", ImageSize -> 1000]}} ]]

This is what I used to create the grid and export it to pdf.

myGrid = Grid[ 
   Partition[
    Column[{"", Style[#, Bold, FontSize -> 36], "", 
        chartTrends[#, 0.9]}, Alignment -> Center] & /@ countryList, 
    4], Alignment -> Center, Frame -> All, 
   FrameStyle -> Directive[LightGray]];
Export["myGrid2.pdf", myGrid]

I've tried with GraphicsGrid instead of Grid, but that creates other problems such as cropping the legend box.

Any clues?

share|improve this question
2  
Could you post a minimal and self-contained piece of code? –  belisarius May 14 '12 at 20:39
    
Hola Belisarius, here –  Zviovich May 14 '12 at 22:12
    
Hola DiegoZviovich –  belisarius May 15 '12 at 1:17

1 Answer 1

up vote 5 down vote accepted

You could try defining myGrid = Grid[..., ImageSize -> All]. Consider for example the following test data

headings = Range[20];
countryList = Cases[CountryData["Countries"], 
   c_ /; CountryData[c, "BorderingCountries"] =!= {}, 1, 8];
salesTrend[c_, p_] := 
 With[{t = CountryData[c, "BorderingCountries"]},
  {t, RandomReal[1, {20, Length[t]}]}]

Then with

myGrid = Grid[Partition[
    Column[{"", Style[#, Bold, FontSize -> 36], "", 
        chartTrends[#, 0.9]}, Alignment -> Center] & /@ countryList, 
    4], Alignment -> Center, Frame -> All, 
   FrameStyle -> Directive[LightGray], ItemSize -> All];

Export["myGrid2.pdf",myGrid]

I get

Mathematica graphics

compared to the original (Note the wrapping of Afghanistan plus the elongated legend)

Mathematica graphics

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.