ggplot2: Legend overlapping the plot area - is it possible to manually adjust legend position?
By : Kevin
Date : March 29 2020, 07:55 AM
I wish this help you In my environment, the legend does not overlap the plot area at all, but anyway what is overlapping is the background of the legend, so you can remove it by: code :
ggplot(carrots,aes(y=Yield,x=Field,fill=Breed)) +
geom_bar() +
opts(legend.direction = "horizontal",
legend.position = "top",
legend.background = theme_blank()) + # this does hack
labs(fill="")
|
Androidplot legend overlapping
By : Carlos Ernesto
Date : March 29 2020, 07:55 AM
it fixes the issue What can I do to fix the legend overlapping in androidplot? , You can use this to enlarge the legend: code :
myPlot.getLegendWidget().setSize(new SizeMetrics(15, SizeLayoutType.ABSOLUTE, 200, SizeLayoutType.ABSOLUTE));
myPlot.position(
myPlot.getLegendWidget(),
0,
XLayoutStyle.ABSOLUTE_FROM_RIGHT,
0,
YLayoutStyle.ABSOLUTE_FROM_BOTTOM,
AnchorPosition.RIGHT_BOTTOM);
myPlot.position(myPlot.getDomainLabelWidget(),
0,
XLayoutStyle.ABSOLUTE_FROM_LEFT,
15,
YLayoutStyle.ABSOLUTE_FROM_BOTTOM,
AnchorPosition.LEFT_BOTTOM);
|
Matlab: flip legend order and legend overlapping plots after saving
By : Ricardo Mawcinitt
Date : March 29 2020, 07:55 AM
To fix the issue you can do The reason for which the code provided in the answer to reverse ordering of legend colors in matlab bar plot does not work in your case is because in that case (plot of a bar chart) the object in the legend are patches while in your plot they are lines. The FaceColor only applies to patches and not to lines. code :
p_h=get(gca,'children')
'NorthOutside' outside plot box near top
'SouthOutside' outside bottom
'EastOutside' outside right
'WestOutside' outside left
'NorthEastOutside' outside top right (default for 3-D plots)
'NorthWestOutside' outside top left
'SouthEastOutside' outside bottom right
'SouthWestOutside' outside bottom left
figure
% Initial plot
h_p=plot(0:.1:2*pi,bsxfun(@plus,sin([0:.1:2*pi]),[3:3:30]'),'linewidth',3)
% Initial legend
[h_leg,b]=legend(cellstr(strcat(repmat('sin(x)+',10,1),num2str([3:3:30]'))))
%
% YOUR CODE TO GENERATE NTHE NEW COLORS
%
map = colormap; % current colormap
n = size(b,1);
z = linspace(size(map,1),1,n/3); % there is 1 text and 2 line elements for every data series, so I divide by 3
z = round(z); %otherwise matlab gets angry that indices must be real integers or logicals
MAP = map(z(:),:); % gets elements specified by linspace from colormap
%
% Reverse the legend strings
%
rev_str=flipud(get(b(1:10),'string'))
%
% Get the handles of the lines in the legend
%
b1=b(11:2:30)
%
% Revere the string in the legend
% and update the color of the lne in the plot using the colors defined in
% MAP
%
p_h=get(gca,'children')
for i=1:10
set(b(i),'string',rev_str{i})
set(p_h(i),'color',MAP(i,:),'linewidth',3)
end
%
% Reverse the color of the lines in the legend
for i=1:10
set(b1(i),'color',MAP(i,:),'linewidth',3)
end
%
% Move the legend outside the axes
%
set(h_leg,'location','NorthEastOutside')
|
d3 chart legend overlapping
By : Jihad MJR
Date : March 29 2020, 07:55 AM
it helps some times I personally always prefer to wrap legends into g component, and translate it based it's content size . That way is more space saving & readable code :
var startX = 30;
legends.each(function(d, i, arr) {
var wrapper = d3.select(this); //this is g
var text = wrapper.select('text');
var bbox = text.node().getBBox();
wrapper.attr('transform', 'translate(' + startX + ')');
startX += bbox.width + 35;
})
|
Overlapping legend in r plot
By : CodeLyokoXtEAM
Date : March 29 2020, 07:55 AM
this will help You should be reading the manual page for legend - ?legend: You have full control over every aspect of of the placement and font size. First, you do not have room for the legend below the x-axis unless you remove the x-axis label or increase the margin at the bottom (?par, argument mar=). The inset= argument in legend adjusts the position so something like inset=c(0, -.15) will put it below the axis, but you will may need to adjust the -.15 up or down. You also need to include xpd=TRUE so that R knows it is all right to put the legend in the margin below the plot. Finally, cex= controls the expansion of the text with 1 being the default: code :
plot(NA, xlim=c(0, 1), ylim=c(0, 1), xlab="")
legend("bottom", "A very long legend under the plot",
xpd=TRUE, inset=c(0, -.15), cex=.8)
|