2
$\begingroup$

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?

$\endgroup$
  • 2
    $\begingroup$ Could you post a minimal and self-contained piece of code? $\endgroup$ – Dr. belisarius May 14 '12 at 20:39
  • $\begingroup$ Hola Belisarius, here $\endgroup$ – Zviovich May 14 '12 at 22:12
  • $\begingroup$ Hola DiegoZviovich $\endgroup$ – Dr. belisarius May 15 '12 at 1:17
5
$\begingroup$

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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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