Skip to main content
The 2024 Developer Survey results are live! See the results

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.

10 votes
2 answers
19k views

Plotly: How to set up multiple subplots with grouped legends?

for each subplot I have 3 seperate line:2017 ,2018 and 2019 with 3 times "go.Scatter", each subplot represents one country (25 countries) with always these 3 years. I can use the subplot ...
0 votes
1 answer
27 views

How to avoid overlapping legends for multiple geom_point layers in ggplot2

I'm trying to create a chart with 2 geom_points and a geom_text_repel layer. When I display my legend, the geom_points overlap. The main data points should be represented as empty circles, while the &...
1 vote
1 answer
30 views

How to Add a Legend to a ggplot with two axes

I've put together this graph and I would like to be able to add a legend to it but can't seem to figure out why it's not showing up and how to easily add it. data <- data.frame(group = LETTERS[1:5],...
116 votes
10 answers
164k views

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 ...
0 votes
1 answer
19 views

Centering a `ggplot2` Plot Legend in a Blank Plot

I have the following graph. ggplot() + geom_hline(aes(yintercept = 0, linetype = "Line 1"), color = "white", size = 1.25) + geom_hline(aes(yintercept = 0, linetype = "Line ...
0 votes
1 answer
54 views

Seaborn catplot legend's background color and border

MWE from matplotlib import pyplot as plt import seaborn as sb df = sb.load_dataset("titanic") g = sb.catplot( data=df, x="who", y="survived", hue="class", ...
4 votes
0 answers
834 views

How to change legend text formatting in Leaflet in R?

I've created a leaflet map and I'm trying to figure out how I can change the formatting of the legend labels. I currently have a gradient color palette to represent the data, with a set of discrete ...
0 votes
1 answer
37 views

Changing the Legend Title in a `ggpointdensity` Density Scatterplot [duplicate]

I have the following data and the following graph. df <- data.frame(col1 = rnorm(1000, 0, 0.05), col2 = rnorm(1000, 0, 0.05)) ggplot(data = df, mapping = aes(x = col1, y = col2)) + ...
0 votes
1 answer
68 views

Add legend after using gg.gap

I have a data set with a big negative value, so I used gg.gap package to make a discontinuous y-axis. The code worked well but after adding the function gg.gap the legend was deleted. I tried adding a ...
114 votes
4 answers
150k views

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, ...
2 votes
1 answer
44 views

How can I make the legend appear on this chart?

I've drawn this quartile for the runoff rate, and I'd like the legend to appear as: - Median and - Q25-Q75. Can you please help me? Runoff <- data.frame(Year = rep(1991:2002, each = 12), ...
0 votes
1 answer
129 views

Combining my two `geom_abline` in ggplot2 to get legend

I have the plot below, using this code (see below for data), but as I'm struggling to get group in the aes call to get a meaningful legend for (the black and the blue line). I am trying to combine the ...
0 votes
0 answers
8 views

Adapting the leaflet.js Choropleth example with non static legend

I am trying to use the beautiful base example Choropleth, but would like to have a second base map, with a second legend that would be linked to the base map used (therefore not anymore static), with ...
1661 votes
18 answers
1.9m views

How to put the legend outside 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 gets ...
-1 votes
1 answer
45 views

Plot X and Y chart with third column as legend for each point in Excel or Google Sheets [duplicate]

I am having difficulty understanding why it is so difficult to do something so simple in R or Python in Excel or Google Sheets. I want to plot Status1 versus Status2 in a simple X and Y plot. However, ...

15 30 50 per page