All Questions

514
votes
16answers
380057 views

How to put the legend out of the plot

I have a series of 20 plots (not subplots) to be made in a single figure. I want the legend to be outside of the box. At the same time, I do not want to change the axes, as the size of the figure ge...
98
votes
2answers
133185 views

Add legend to ggplot2 line plot

I have a question about legends in ggplot2. I managed to plot three lines in the same graph and want to add a legend with the three colors used. This is the code used library(ggplot2) require(RCu...
131
votes
9answers
233507 views

Plot a legend outside of the plotting area in base graphics?

As the title says: How can I plot a legend outside the plotting area when using base graphics? I thought about fiddling around with layout and produce an empty plot to only contain the legend, but I ...
82
votes
7answers
40881 views

Add a common Legend for combined ggplots

I have two ggplots which I align horizontally with grid.arrange. I have looked through a lot of forum posts, but everything I try seem to be commands that are now updated and named something else. M...
3
votes
2answers
5078 views

How to display legend for Pie Chart in columns?

I have a PieChart with many sections, legend for this PieChart renders as one row. How to render legend as two columns?
134
votes
3answers
83548 views

Moving matplotlib legend outside of the axis makes it cutoff by the figure box

I'm familiar with the following questions: Matplotlib savefig with a legend outside the plot How to put the legend out of the plot It seems that the answers in these questions have the luxury of be...
61
votes
1answers
28964 views

Control ggplot2 legend look without affecting the plot

I'm plotting lines with ggplot2 like this: ggplot(iris, aes(Petal.Width,Petal.Length,color=Species)) + geom_line() + theme_bw() . I find legend marks to be small so I want them to be bigger. If I ...
152
votes
6answers
103013 views

Secondary axis with twinx(): how to add to legend?

I have a plot with two y-axes, using twinx(). I also give labels to the lines, and want to show them with legend(), but I only succeed to get the labels of one axis in the legend: import numpy as np ...
45
votes
4answers
14793 views

ggplot2 keep unused levels barplot

I want to plot unused levels (that is, levels where the count is 0) in my bar-plot, however, unused levels are dropped and I cannot figure out how to keep them df <- data.frame(type=c("A", "A", "A...
12
votes
2answers
10772 views

ggplot separate legend and plot

I am using the grid lpackage to place my graphs that I made with ggplot2: library(ggplot2) library(grid) Layout <- grid.layout(nrow = 4, ncol = 4, widths = unit(1, "null"), ...

Previous Next