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

All Questions

Tagged with
0 votes
2 answers
81 views

How do I add a graphical legend to the bottom of a figure using ggplot?

I am interested in creating a figure using ggplot2 similar to the one drafted here. I have created the top section using ggplot and facet_wrap but have yet to find a way to add a tiled legend to the ...
Wilson King's user avatar
0 votes
0 answers
66 views

Add general label to facets ggplot2

I am trying to add a general legend to facets in a plot. But I can´t. I was looking but the nearest question is this: How do you add a general label to facets in ggplot2?. Anyway, this it isn't an ...
Kevin Santos's user avatar
0 votes
1 answer
326 views

ggplot2: space legend per facet grid / manipulate position of individual legend entries [duplicate]

I have following code: ggplot(data = mpg[is.element(mpg$manufacturer, c("audi", "dodge", "ford")),], mapping = aes(x = year, colour = manufacturer)) + geom_line(stat = &...
pgitti's user avatar
  • 87
2 votes
2 answers
853 views

ggplot: Separate legend for both a geom_vline and geom_hline

I'm trying to make a separate legend for geom_vline and geom_hline in a ggplot with facets. Here is my code: set.seed(1) vec1 = rnorm(20) set.seed(2) vec2 = rnorm(20) set.seed(3) vec3 = rnorm(20) vec ...
AlexLee's user avatar
  • 441
2 votes
1 answer
1k views

How to add greek letters to Facet_Grid strip labels?

I have created the plot below using facet_grid and have used the labeller argument to add "p=" and "mu[2]" labels to the gray strips around the grid. I would like to replace "...
Salivan's user avatar
  • 167
0 votes
1 answer
300 views

is there a way to show the same legend for each facet in ggplot2

reproducible example: library(datasets) library(tidyverse) data(iris) iris$facet <- "A" A <- iris iris$facet <- "B" B <- iris iris <- rbind(A,B) iris %>% ...
Jakn09ab's user avatar
  • 179
4 votes
1 answer
2k views

R: Reliable conversion between gtable and ggplot objects. How to make lemon::reposition_legend() work after ggplot_build()?

I have a pretty complicated case at hand with ggplot2. I tried to exemplify it with a MWE using iris data below. I just have boxplots in facets, and wanted to move the legend to take the space of the ...
DaniCee's user avatar
  • 2,859
3 votes
0 answers
7k views

ggplot different legends for different facets

I'd like to use different legends for 2 of the facets in this plot. The facets for 'Sharks' and 'Tunas' include multiple fish species, so I would like each facet to contain a unique legend for those ...
ament's user avatar
  • 83
2 votes
1 answer
3k views

Display the legend inside the graph when wrapping with ggplot2

How can I do... ... instead of the default ... ?
Arthur's user avatar
  • 1,228
7 votes
1 answer
10k views

How to add a label for a vertical line with legend in ggplot2

R 3.1.2/ggplot2_1.0.0/Windows7 How can one add 2 vertical lines with legends in a faceted graph without them changing the linetype? In the following example i can't get the legends to appear as I ...
Panchito's user avatar
  • 347
68 votes
1 answer
49k views

R ggplot2 legend inside the figure

So, I have the following data.frame, and I want to generate two plots in one graph for yval vs. xval, for each zval and type tp. The lef > df xval yval se zval cond 1 1.0 ...
Vahid Mirjalili's user avatar
34 votes
5 answers
29k views

Place a legend for each facet_wrap grid in ggplot2

I have this data frame: x <- data.frame( Date = factor(rep( c("12/1/2011", "1/2/2012", "2/1/2012", "2/10/2012", "2/13/2012"), 3 )), ...
user1471980's user avatar
  • 10.5k