2
$\begingroup$

I tried using Placed[legend,{1,0.5}] but it leaves some unnecessary gap between the right frame boundary and the legend. I know there is a way to use nested position specification {{1,0.5},{something,something}} but don't understand it. Can someone please help me. Is there a way to specify the exact gap to leave between the legend and the right frame boundary.

Below is an example where the legend can be placed immediately to the right of right frame with {{1,0.5},{0.2,0.5}} but i want to figure it out for any rectangular graph? A general method or builtin option.

data = {{{1, 1}, {1, 2}, {2, 3}}, {{1, 1}, {2, 1}, {1, 1}}};
Show[
 RectangleChart[data, PlotTheme -> "Detailed", 
  ChartLegends -> Placed[{"A", "B", "C"}, {1, 0.5}]],
 RectangleChart[data, PlotTheme -> "Detailed", 
  ChartLegends -> Placed[{"A", "B", "C"}, {{1, 0.5}, {0, 0.5}}]],
 RectangleChart[data, PlotTheme -> "Detailed", 
  ChartLegends -> Placed[{"A", "B", "C"}, {{1, 0.5}, {0.1, 0.5}}]],
 RectangleChart[data, PlotTheme -> "Detailed", 
  ChartLegends -> Placed[{"A", "B", "C"}, {{1, 0.5}, {0.2, 0.5}}]],
 ImageSize -> Full
 ]

The reason i want to find a way to get the legend exactly on the right frame so i can then manually specify the distance between the frame and legend. I have a lot of graphs being generated automatically and they look weird unless i can specify the exact distance.

$\endgroup$
  • 1
    $\begingroup$ Please edit this question and add a minimal working example of code that illustrates your problem. $\endgroup$ – m_goldberg Sep 21 '17 at 15:48
  • $\begingroup$ I have added a minimal working example $\endgroup$ – user13892 Sep 21 '17 at 16:12
4
$\begingroup$

I don't understand your example code, but I think what you are looking for is the Scaled function, which you can learn about in the documentation. All you need to do is determine your offset and add it to 1 in the Scaled function's x-position, which will put the legend to the right of the graph:

data = {{{1, 1}, {1, 2}, {2, 3}}, {{1, 1}, {2, 1}, {1, 1}}};
legendoffset = 0.01;
Show[RectangleChart[data, PlotTheme -> "Detailed", 
  ChartLegends -> 
   Placed[{"A", "B", "C"}, Scaled[{1 + legendoffset, 0.5}]]], 
 ImageSize -> Full]

graph

$\endgroup$
  • $\begingroup$ by specifying the barspacing I can calculate the horizontal distance from the start of first bar to the end of last bar but is there a way to know the distance at the edges until the frame boundary. Also is there a way to completely eliminate it? $\endgroup$ – user13892 Sep 21 '17 at 20:44
  • $\begingroup$ @user13892 I don't know why you would need to "calculate" what the edge is. Using the Scaled function, the right side of the graph, regardless of size, corresponds with a 1 in the x-position of the function. It seems to me that's all you need for what you're trying to do. And eliminate what? $\endgroup$ – Haff Sep 22 '17 at 1:45

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.