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

All Questions

Tagged with
1 vote
1 answer
115 views

How do I move and unstack legend elements when using ggplot and ggpattern?

I have data with two different categorical grouping variables, and to distinguish between them, I followed this guide to add a pattern to one of the categorical variable types. However, now that I've ...
wlane's user avatar
  • 13
0 votes
1 answer
47 views

ggplot2 - wrap data around legend in custom position

When placing a legend in a custom position (using legend.position = c(x, y)) in a ggplot, is it possible to format the legend so that it does not overlay the data, and instead, the datapoints wrap ...
Sean's user avatar
  • 125
0 votes
1 answer
515 views

How to combine colour and linetype into a single legend?

I am trying to combine two legends of unequal length into a single length and am having some problems. I am using colour to represent 3 different populations, whereas I'm using linetype to show ...
Jackson Young's user avatar
1 vote
1 answer
402 views

How can I completely remove legend.key from ggplot2 legend?

I'm plotting a graph and I need to completely remove the legend.key from my ggplot legend. Why I need to do this? The legend starts with a number that reference the X axis breaks, and the label its ...
Vinícius Neres's user avatar
1 vote
0 answers
1k views

How do I stop a ggplot graph legend from getting cut off on the right when exporting-saving when using showtext?

Just started R a couple weeks ago. Getting familiar with ggplot. I successfully made the graph I wanted to including all legends, axes titles, etc. I'm able to export/save this image fine. However, ...
Jeff's user avatar
  • 11
0 votes
1 answer
68 views

(R) How to get a legend in ggplot2 based on color, linetype and point shape?

How can I get a legend for the following data based to differentiate y1 and y2 based on color, linetype, and shape of points? (sd just means standard deviation) x <- c(2.5, 1.25, 0.625, 0.3125, 0....
Brian's user avatar
  • 11
0 votes
0 answers
99 views

How to add colour-coded figure legend on mirrored bar chart in ggplot? [duplicate]

I have created a mirrored bar chart to compare two variables. I have managed to get each of these a different colour, but haven't had any success with getting a figure legend to explain what each part ...
Anna's user avatar
  • 1
1 vote
0 answers
247 views

Adding a Legend in R map graph

i have the following map, which was built from the data on the library "maps". it is basically the distance among all counties at USA and some important airports, the thing is that I haven't ...
Cristian Tellez Montoya's user avatar
1 vote
1 answer
487 views

Side by Side plot with one legend in ggplot2

I would like to know how to use ggplot2 to create a side by side plots with one common legend. I have seen some similar questions but not sure how to directly apply it to my code. I have provided my ...
Shem Katz's user avatar
0 votes
1 answer
39 views

Adding a Legend in ggplot2

I have the following code. Financial_Wealth.lq,Financial_Wealth.uq,Total_Wealth.lq,Total_Wealth.uq,time=seq(0,(sPar.dNN),1)) ggplot(data, aes(x=time)) + geom_line(aes(y = Human_Capital.mean), ...
Shem Katz's user avatar
0 votes
1 answer
168 views

Add a combined legend that accounts for color, shape, and linetype, while keeping the original legends

I have the following df: df <- data.frame("id" = c("A1", "A1", "A1", "A2", "A2", "A2", "B1", "B1", "B1&...
Thredolsen's user avatar
2 votes
1 answer
250 views

Is there a function in R to combine two legends of a graph that's build from multiple dataframes?

I am trying to merge the legends of a plot, but I can't figure out how. I looked up many examples, but in these examples people build the plots from one dataframe. My plot is build from four ...
Iris's user avatar
  • 23
1 vote
2 answers
1k views

How can I change the labels in the legend?

I would like to change the labels in the legend from 1, 2, 3, 4 to specific labels like "stable low", "treatment increasing", ... But it just won't work. Any ideas? I tried ...
dieanja's user avatar
  • 13
1 vote
1 answer
1k views

ggplot2's line legends appear "crossed-out"

I'm creating a ggplot with two lines, each from separate geoms. As an example: df = data.frame( x.v = seq(0, 1, 0.025), y.v = runif(41) ) straight.line = data.frame( Inter = c(0), Slope = ...
GMSL's user avatar
  • 395
1 vote
1 answer
86 views

Adding a legend with ggplot failed

I try to add a legend to my chart using scale_color_manual but when I use it as seen below, it just simply is not there. To color the lines gradiently (not sure if it is the right word) I use color =...
schande's user avatar
  • 608

15 30 50 per page