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 want to chart data using a BarChart, the labels on the x-axis should consist of three values, however I can only use one of the values (the street name), where I would like to include the city and country name.

The relevant piece of code:

rEntities = {{1261, "C/O C T Corporation System", "Boston", 
"UNITED STATES"}, {1017, "C/O National Registered Agents, Inc.", 
"New York", "UNITED STATES"}, {1004, "49, Avenue J.F. Kennedy", 
"Luxembourg", "LUXEMBOURG"}, {799, 
"C/O National Corporate Research, Ltd.", "Dover", 
"UNITED STATES"}, {793, "C/O CT Corporation System", "Boston", 
"UNITED STATES"}}

BarChart[#, ChartStyle -> "DarkRainbow", 
PlotLabel -> Framed[Text[Grid[{
    {Style["Entities with same address", Blue, FontSize -> 18]},
    {Style["Address's with 200 to 6999 entities", Red, 
      FontSize -> 12]}}]]], 
ChartLabels -> (Placed[
  Rotate[Style[#, Black], Pi/3] & /@ #2, {{.7, 0}, {1, 1}}])] & @@
Transpose[rEntities]

only 1 field on x-axis

What I would like to see would be the city and country as well. For example: "C/O C T Corporation System, Boston, UNITED STATES" under the blue bar. "49, Avenue J.F. Kennedy, Luxembourg, LUXEMBOURG" under the olive bar, etc.

Thank you in advance!

share|improve this question

2 Answers 2

Replace #2 with an array containing the information you are interested in (e.g. Transpose[{#2, #3}] and then use Column[#] to format the label as desired.

rEntities = {{1261, "C/O C T Corporation System", "Boston", 
   "UNITED STATES"}, {1017, "C/O National Registered Agents, Inc.", 
   "New York", "UNITED STATES"}, {1004, "49, Avenue J.F. Kennedy", 
   "Luxembourg", "LUXEMBOURG"}, {799, 
   "C/O National Corporate Research, Ltd.", "Dover", 
   "UNITED STATES"}, {793, "C/O CT Corporation System", "Boston", 
   "UNITED STATES"}}

BarChart[#, ChartStyle -> "DarkRainbow", 
   PlotLabel -> 
    Framed[Text[
      Grid[{{Style["Entities with same address", Blue, 
          FontSize -> 18]}, {Style[
          "Address's with 200 to 6999 entities", Red, 
          FontSize -> 12]}}]]], 
   ChartLabels -> (Placed[
      Rotate[Style[Column[#, Alignment -> Right], Black], Pi/3] & /@ 
       Transpose@{#2, #3}, {{.7, 0}, {1, 1}}])] & @@ 
 Transpose[rEntities]

Mathematica graphics

share|improve this answer

Something like this?

BarChart[#, ChartStyle -> "DarkRainbow", 
 PlotLabel -> Framed[Text[Grid[{
    {Style["Entities with same address", Blue, FontSize -> 18]},
    {Style["Address's with 200 to 6999 entities", Red, 
      FontSize -> 12]}}]]], 
    ChartLabels -> (Placed[
       Rotate[Style[Row[Riffle[#, ", "]], Black, 8], Pi/5] & /@ Transpose[{#2, #3, #4}], {{.7, 0}, {1, 1}}])] & @@
 Transpose[rEntities]

Change value of Placed:

BarChart[#, ChartStyle -> "DarkRainbow", 
 PlotLabel -> Framed[Text[Grid[{
    {Style["Entities with same address", Blue, FontSize -> 18]},
    {Style["Address's with 200 to 6999 entities", Red, 
      FontSize -> 12]}}]]], 
    ChartLabels -> (Placed[
       Rotate[Style[Row[Riffle[#, ", "]], Black, 8], Pi/2] & /@ Transpose[{#2, #3, #4}], Below])] & @@
 Transpose[rEntities]

or use ChartLegends:

BarChart[#, ChartStyle -> "DarkRainbow", 
 PlotLabel -> Framed[Text[Grid[{
    {Style["Entities with same address", Blue, FontSize -> 18]},
    {Style["Address's with 200 to 6999 entities", Red, 
      FontSize -> 12]}}]]], 
    ChartLegends -> (Placed[
       Style[Row[Riffle[#, ", "]], Black, 8] & /@ Transpose[{#2, #3, #4}], Below])] & @@
 Transpose[rEntities]
share|improve this answer
    
I like your solution the best, however when using it where there are 50 columns I need to rotate the label's so they are vertical and under their respective bar. –  sente Jan 6 at 3:11
    
I tried code BarChart[#, ChartStyle -> "DarkRainbow", AspectRatio -> .3, ImageSize -> 600, PlotLabel -> Framed[Text[ Grid[{{Style["Entities with same address", Blue, FontSize -> 18]}, {Style[ "Address's with 200 to 6999 entities", Red, FontSize -> 12]}}]]], ChartLabels -> (Placed[ Rotate[Style[Row[Riffle[#, ", "]], Black, 10], Pi/2] & /@ Transpose[{#2, #3, #4}], {{4, 0}, {3, 1}}])] & @@ Transpose[rEntities] –  sente Jan 6 at 3:12
    
@sente I added that option –  halmir Jan 6 at 13:31
    
Thank you for your help! –  sente Jan 6 at 15:17

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.