Questions tagged [legend]

A graph legend is commonly used when plotting several sets of data within the same diagram. The legend associates each plot with its corresponding data.

A legend attached to a graph (or other visualization of data) is used to explain the graphical language (colors, symbols, lines, etc) of the specific visualization.

In scientific software for statistical computing and graphics and also , function legend adds a legend box to an existing plot.

4990 questions
126
votes
4 answers

Keep unused levels in bar plot

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", "B", "B"), group=rep("group1", 5)) df$type <-…
Ulrik
  • 1,575
  • 2
  • 10
  • 10
125
votes
4 answers

Remove extra legends in ggplot2

I have a simple data frame that I'm trying to do a combined line and point plot using ggplot2. Supposing my data looks like this: df <- data.frame(x=rep(1:10,2), y=c(1:10,11:20), group=c(rep("a",10),rep("b",10))) And I'm trying to…
Wilduck
  • 13,822
  • 10
  • 58
  • 90
114
votes
8 answers

Plot labels at ends of lines

I have the following data (temp.dat see end note for full data) Year State Capex 1 2003 VIC 5.356415 2 2004 VIC 5.765232 3 2005 VIC 5.247276 4 2006 VIC 5.579882 5 2007 VIC 5.142464 ... and I can produce the following…
Hugh
  • 15,521
  • 12
  • 57
  • 100
113
votes
5 answers

Show only certain items in legend

I currently am plotting a stacked bar graph of a large amount of taxonomic data, and only wish to show significant species in the legend (out of ~500 I wish to show ~25). Is there a simple way to do this? Below is the code I…
Funsaized
  • 1,972
  • 4
  • 21
  • 41
109
votes
2 answers

Legend on bottom, two rows wrapped in ggplot2 in r

library(ggplot2) library(scales) library(reshape2) Rdates <- c("2007-01-31","2007-02-28","2007-03-30","2007-04-30","2007-05-31","2007-06-29","2007-07-31","2007-08-31","2007-09-28","2007-10-31") Rdates <- as.Date(Rdates) Cnames <- c("Column 1…
Trevor Nederlof
  • 2,546
  • 5
  • 22
  • 40
109
votes
6 answers

Stop matplotlib repeating labels in legend

Here is a very simplified example: xvalues = [2,3,4,6] for x in xvalues: plt.axvline(x,color='b',label='xvalues') plt.legend() The legend will now show 'xvalues' as a blue line 4 times in the legend. Is there a more elegant way of fixing…
Anake
  • 7,201
  • 12
  • 45
  • 59
107
votes
7 answers

How is order of items in matplotlib legend determined?

I am having to reorder items in a legend, when I don't think I should have to. I try: from pylab import…
CPBL
  • 3,783
  • 4
  • 34
  • 44
106
votes
4 answers

How to move or position a legend in ggplot2

I'm trying to create a ggplot2 plot with the legend beneath the plot. The ggplot2 book says on p 112 "The position and justification of legends are controlled by the theme setting legend.position, and the value can be right, left, top, bottom, none…
Dan Goldstein
  • 24,229
  • 18
  • 37
  • 41
105
votes
4 answers

matplotlib: 2 different legends on same graph

I have a plot where different colors are used for different parameters, and where different line styles are used for different algorithms. The goal is to compare the results of the different algorithms performed with similar parameters. It means in…
Charles Brunet
  • 21,797
  • 24
  • 83
  • 124
99
votes
2 answers

How to edit a seaborn legend title and labels for figure-level functions

I've created this plot using Seaborn and a pandas dataframe (data): My code: import seaborn as sns g = sns.lmplot('credibility', 'percentWatched', data=data, hue='millennial', markers=["+", "."], x_jitter=True, y_jitter=True,…
Oliver G
  • 1,021
  • 2
  • 9
  • 20
95
votes
5 answers

Matplotlib scatter plot legend

I created a 4D scatter plot graph to represent different temperatures in a specific area. When I create the legend, the legend shows the correct symbol and color but adds a line through it. The code I'm using is: colors=['b', 'c', 'y', 'm', 'r'] lo…
user2386081
  • 1,087
  • 3
  • 10
  • 9
93
votes
5 answers

HighCharts Hide Series Name from the Legend

I try to solve this problem several times and give up. Now, when I have met him again, I decided to ask for some help. I have this code for my Legend: legend: { layout: 'vertical', align: 'right', verticalAlign: 'top', x: -10, y:…
gotqn
  • 42,737
  • 46
  • 157
  • 243
92
votes
8 answers

Move seaborn plot legend to a different position

I'm using factorplot(kind="bar") with seaborn. The plot is fine except the legend is misplaced: too much to the right, text goes out of the plot's shaded area. How do I make seaborn place the legend somewhere else, such as in top-left instead of…
user124114
  • 8,372
  • 11
  • 41
  • 63
89
votes
9 answers

Making a Legend/Key in GraphViz

I’d like to include a legend or key in my GraphViz diagram. I’m having trouble figuring out what code to use, though. I also want to put it in a corner, but the only coord I know for sure is the bottom-left: pos="10,10!". Does anyone know how I can…
Synetech
  • 9,643
  • 9
  • 64
  • 96
85
votes
4 answers

creating over 20 unique legend colors using matplotlib

I am plotting 20 different lines on a single plot using matplotlib. I use a for loop for plotting and label every line with its key and then use the legend function for key in dict.keys(): plot(x,dict[key], label = key) graph.legend() But using…
msohail
  • 1,085
  • 2
  • 13
  • 14