5,200 questions
6
votes
1
answer
96
views
How can I ensure legends take up the full width?
I am trying to customize the behavior of a horizontal legend in Plotly.js for varying viewport widths.
Minimal example:
<head>
<script src="https://cdn.plot.ly/plotly-latest.min.js&...
2
votes
1
answer
63
views
How to make my plot legend be inside the axis?
I would like the legend to my scatter/line plot to be inside the axis of the plot it is informing, but I can only seem to get a legend if is has its own axis, which becomes a problem when I want three ...
0
votes
1
answer
51
views
Automatically color points by variable without showing legend, keep separate line legend in ggplot
I want to plot points in ggplot2 with colors mapped to a variable (director), but I don’t want a legend for the points. At the same time, I have a line (geom_smooth) colored by another variable (...
0
votes
0
answers
103
views
"UserWarning: No artists with labels found to put in legend" Error when trying to create a legend with labels from dataset
I can't get legend labels to show up when I use 'CONDITION' (a longer string) as my x data and hue, however when I use CONDITION_N (a shorter string) as the hue then it appears. Why?
Warning:
/var/...
2
votes
2
answers
129
views
How can I change the order of legend items to match the stacked bars in lattice::barchart?
I wish to reverse the order in which the items in the auto.key-generated legend of my bar chart are displayed so they are in the same order as the items in the bar chart. I have tried adding "...
0
votes
0
answers
55
views
Drawing Color Bar Legends in R [duplicate]
I came across a unique colorbar in an article, but the author didn't include the code. It seems to incorporate some features of ggplot2, but how is this two-ended, interrupted triangle drawn? Does ...
0
votes
0
answers
40
views
Inconsistent legend overflow in Chart.js 3.7
I have a line chart built in chart.js 3.7. The legend items at most screen widths need to overflow into a second line. However, this only happens about 50% of the time the chart loads.
The first image ...
1
vote
1
answer
70
views
Add a legend with size on ggplot map
I am trying to get the following legend:
"towns" as yellow triangles
"islands" as green circles of different size depending on... well "size" (actually population size)
...
0
votes
0
answers
69
views
Pine Script v6: How to make indicator legend background transparent to match pane background?
I've created a Pine Script indicator with a custom pane background colour using bgcolor(). The background displays correctly, but the indicator legend area (showing indicator name and values) has its ...
6
votes
1
answer
145
views
More than one dot in legend
I have created the first figure using legend normally.
I would like to have more than one dot in the legend, so the colours are easier to recognize there, as in the second figure (which I created ...
2
votes
2
answers
107
views
Hide legend labels with underscore in matplotlib>3.10
I create a plot with seaborn that has several lines and error bands. In the legend, I only want to show some of the labels and hide others.
Previously, it was possible to call ax.legend(['one', '_', '...
3
votes
1
answer
120
views
Legend grouping not working with fig.add_shape
I’m using Plotly to create some subplots, where I have several vertical lines and shapes that I want to toggle at the same time. The vertical lines were plotted using traces, so the legendgroup worked ...
3
votes
1
answer
77
views
R ggplot2 change legend display to left-to-right
I have a legend for a ggplot chart that spans two rows with several short values and one long value:
legend over two rows
Currently legend 'fills' by column then by row, causing the wrapping to mess ...
0
votes
2
answers
101
views
Place the shared legend inside the plot grid as opposed to besides it [duplicate]
I have 3 plots that I want to arrange in a 2x2 format. They all share the same legend, and I want to place the legend in the bottom right space, where a fourth figure would fit. So far, I have tried ...
2
votes
3
answers
103
views
Drawing a vertical line in Gnuplot and adding a key/legend to it
reset
set encoding utf8
set terminal pdfcairo size 20cm,20cm font "STIX Two Math, 22" enhanced
set output "straight-lines.pdf"
#
set grid linetype 0 linewidth 1 dashtype 3 ...
3
votes
2
answers
134
views
How to change the pattern background in legend keys?
I need to use colours and patterns independently to properly display my data, for this I use geom_col_pattern(). The issue I have is that in the legend the background is so dark, that the pattern is ...
2
votes
2
answers
59
views
How to change legend patches after plotting?
I have a function that is supposed to enlarge all labels in a figure to make it ready for export. However I fail to enlarge the legend properly:
import matplotlib.pyplot as plt
def enlarge_legend(ax, ...
0
votes
0
answers
52
views
Plotly subplots legend issues with Pandas dataframe
I have a dataframe (df) with two y-axis columns (numeric, A and B), three x-axis columns (K, L, M), and a label (string) column.
Column M is also used to color-code the data points. It is discrete (i....
2
votes
1
answer
74
views
How do I get tmap legends to play nicely with subscripts, italics, etc.?
When I use expression() to add text formatting such as italics and subscripts to a tmap legend, I'm getting huge amounts of unnecessary white space, and I have no idea why.
Here's my reprex code;
...
1
vote
2
answers
117
views
Assigning patterns in the legend only to the patterned columns
I have a bar plot where I am using ggpattern to assign patterns to the columns. However, I would like only some of the columns (chosen arbitrarily) to have patterns. To do so, I am assigning values ...
0
votes
1
answer
85
views
bubble map add legend
I first converted my continuous data into discrete data, then plotted a bubble chart. Color represents intensity, and size represents duration.When I plot a bubble chart using discrete data, the ...
0
votes
2
answers
223
views
ggplot legend: combining fill, color and shape and showing only selected variables
I am trying to make a plot that combines bars with points (of different colors and shapes). Therefore, I need to combine fill, color and shape in the same legend. I am close to my desired result, ...
0
votes
1
answer
57
views
Increase margins of common legend from ggpubr
I am trying to increase the size of the margins of a common legend built when using ggarrange. I could increase the width of the plot, but I do not really want to do that. What do you suggest?
...
1
vote
0
answers
22
views
Adding legend to ggplot()-based chart [duplicate]
My ggplot chart has two different data frames depicted by lines, see code below. I cannot add a legend to it. What I am doing wrong here? Thanks!
library(ggplot)
df1 <- data.frame(YEAR=c(1990:2025)...
-1
votes
1
answer
42
views
How to remove extra legend in ggsurvplot_facet? [closed]
My plot is almost perfect. But ggsurvplot_facet doesn't seem to work like ggplot (I've made this work in basic ggplot before), and it's been giving me endless problems. I want to have only one ...
2
votes
1
answer
103
views
How to display a legend when plotting a GeoDataFrame
I have a GeoDataFrame I want to plot. This works fine, however somehow I cannot easily plot its legend. I have tried a number of alternatives and checked solutions from googling and LLM, but I do not ...
1
vote
1
answer
74
views
How to change line and marker style in a legend?
My script generates a composite plot, made of dozens of lines and line segments. I am trying to add a custom legend to the plot, which contains just 3 of those lines, but I don't seem to be able to ...
2
votes
2
answers
84
views
theme_grey() overwritten theme()
I am running into some trouble trying to fix what I have prescribed using theme(), followed by theme_grey().
For instance, if I were to set
ggplot() +
theme(legend.position = "bottom") +
...
0
votes
1
answer
78
views
How to combine and position title and legend in tmap in R?
I am struggling to place the title inside the frame of the legend, but on top of the legend and not below. Any guidance or working examples would be greatly appreciated! Thank you. The online help isn'...
0
votes
0
answers
69
views
How to make Plotly figure legend be right to left instead of left to right
I have this plot with horizontal legend. I want the legend title to be on the right instead of the left, and I want the bullets of each legend item to be on the right of the name instead of on the ...
1
vote
1
answer
57
views
Create a legend taking into account both the size and color of a scatter plot
I am plotting a dataset using a scatter plot in Python, and I am encoding the data both in color and size. I'd like for the legend to represent this.
I am aware of .legend_elements(prop='sizes') but I ...
2
votes
1
answer
58
views
Want single legend when plotting multiple datasets and using ggnewscale
I want to plot a dataset and then overlay a subset of the dataset in grey. I am using ggnewscale to colour the subset differently. The plot is as desired but I would like to remove the legend with ...
0
votes
0
answers
96
views
How to create a shared legend between plots that don't share all categories [duplicate]
I am trying to create a panel of scatterplots displaying different subsections of the same dataset. I want to combine all of their legends, but because of the subsetting, no individual plot contains ...
1
vote
1
answer
98
views
How to get a discrete colour bar for plotly Scatter plot?
I have defined a list of 5 colours, which I use to colour the markers in the go.Scatter plot below.
I want the colour bar (legend) to show these discrete values, but the resulting colour bar stays ...
0
votes
1
answer
122
views
How to left-justify legend text in leaflet with reactive rasters?
I’ve created a shiny app with raster layers plotted over a leaflet map. The user selects which raster to show with two drop down menus: one to select the type of data (mean or SD) the other to select ...
0
votes
1
answer
90
views
drop = TRUE shows unused level in legend, but no point [duplicate]
ggplot changed how it handles levels with no data and I can't get the plot I want
the third plot shows the unused level in the legend but has no point
I would like to generate the third plot so that ...
1
vote
1
answer
45
views
Parameters for the ggplot theme function about legend.axis.line
Does anyone know the main purpose of the parameter legend.axis.line?
Feel similar to legend.ticks?
And I can't seem to find a use for it yet.
In which case would it be used?
ggplot(mtcars, aes(x = cyl,...
2
votes
0
answers
41
views
Figures with shared legend - Bokeh
I would like to do two figures, coming from the same dataframe, with a shared legend.
The main goal is to be able to have one single legend for both plots and to hide data with the click_policy='hide' ...
2
votes
1
answer
118
views
Collecting common legends while keeping a specific legend beside each plot in patchwork
I am making a multi-panel figure in R using wrap_plots from the patchwork package, and I'd like to have the final plot show a common legend for point shape and color, but have each plot keep its own ...
0
votes
2
answers
106
views
How do I superimpose a legend on a ggplot2 graph? [duplicate]
I want to place a legend inside a ggplot2 graph. See for example the code
ggplot(iris, aes(Sepal.Length, Petal.Width, shape = Species, colour = Species)) +
geom_point() +
theme(legend.position....
0
votes
3
answers
96
views
How to remove the symbol part before text in legend in matplotlib
I added these custom legends in the attached plot, but it has a weird space in front of the text. Is there a way I can remove the empty space?
Code:
# Plotting
plt.figure(figsize=(7, 5)) # Set figure ...
0
votes
0
answers
10
views
dimple js : How to hide the last legend item?
I have a graph with yearly series like "2023, 2024, 2025, 2025 forecast".
In the legend, I would like to hide the last item (i.e. 2025 forecast), but the serie to remain printed.
How can I ...
2
votes
2
answers
67
views
make ggplot legend correspond to geom type
Let's say I need to plot two sets ("types") of data with the same units, where each type has a group a and group b. I want group (a,b) to correspond to color, but I want the type (A, B) to ...
0
votes
0
answers
49
views
Strange `a` on the legend of a `ggplot2` graph [duplicate]
I am doing a linear interpolation using ggplot2, with two series which generates a legend, reporting Primer A and Primer B.
On the legend appears a strange a on the left of the symbol which I am not ...
0
votes
1
answer
45
views
Custom sort order on dynamic legend items for ggpattern and ggplot items
I'm trying to sort legend entries across both ggplot and ggpattern items. The map will not always include all the layers, so the legend should be dynamic - only showing legend items for those layers ...
0
votes
1
answer
55
views
Creating ggplot2 map with overlapping features and configuring legend
I am creating a series of species range maps. In some cases, there will be overlapping features for species that occur in different seasons. So far, the best way I have found to represent this is with ...
1
vote
0
answers
74
views
Why this LIST error with legend in wxplot2d
About two years ago the following code was working without error:
F(q,r):=3*r^2 + 5*q;
wxplot2d(F(1,r),[r,0,5],[legend,"F"],[xlabel,"r[bohr]"], [ylabel,"denso"]);
Now ...
2
votes
1
answer
32
views
Specify the Position of the Legend Title / Variable Name with Legend on Top with Seaborn
When I move the legend of a Seaborn plot from its default position to the top of the plot, I want to have the variable (hue) name in the same row as the possible variable values.
Starting from this ...
4
votes
1
answer
110
views
How to add manual legend to ggplot that is not part of any scale?
I want to add a legend of p value significance to my plot, which is added using stat_pvalue_manual. The label is not part of any aesthetic mappings. Here is some mock code:
stat.df <- data.frame(...
0
votes
1
answer
83
views
change ggplot legend title with common aesthetics
This happens a lot to draw a ggplot with multiple aesthetic all referring to one variable. Then, to change the common legend title, the simple way I know is to do it for all common aesthetics using ...