reproducible example:
library(datasets)
library(tidyverse)
data(iris)
iris$facet <- "A"
A <- iris
iris$facet <- "B"
B <- iris
iris <- rbind(A,B)
iris %>%
ggplot(aes(x = Sepal.Width, y = Sepal.Length, color = Species))+
geom_line()+
facet_wrap(.~facet)+
theme(legend.position = c(0.4,0.6))
I have been asked to make a plot where this same legend is positioned on top of each facet. So the same identical legend that I have put at c(0.4,0.6)
. I don't mind having to specify exact position for each time I have to repeat the label, but I can't make it work. The only suggestions I have is using the directlabels package to label the lines. But this is not acceptable to those making the decision. I know that the default is to show this only once for the entire plot, but we think it would make it easier to interpret if we show this once for every facet.
I don't like using grid.arrange as I have seen suggested - this will make it difficult to align the facets and share y axis etc. (since in my actual figure the y-axis are different)
Just to put it in other words I want the same label shown in A facet shown in the B facet at the same time.