Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom legend in ggpairs dissapears after change of theme. #417

Open
sardanza opened this issue May 11, 2021 · 1 comment
Open

Custom legend in ggpairs dissapears after change of theme. #417

sardanza opened this issue May 11, 2021 · 1 comment
Labels

Comments

@sardanza
Copy link


I add a legend inside the top part of a lower triangular ggpairs with putPlot() as follows:
First I create a ggpairs plot without legend then I strip the legend I want from and ad hoc auxiliary graph and place in the ggpairs plot it with putPlot. It works nicely until I try to modify the theme which makes the legend disappear.

library(GGally)
library(ggplot2)

plotwithoutlegend <-ggpairs(
    iris,
    columns=1:4,
    switch="both",
    upper="blank",
    mapping=aes(color = Species,
                shape= Species,
                fill=Species, 
                alpha=0.5)
)

#2 grab the legend from a graph with the legend I want (without alpha).

auxplot <- ggplot(iris, aes(x=Petal.Length, y=Petal.Width, 
                      color=Species, 
                      shape=Species,
                      fill=Species)) + geom_point()
mylegend <- grab_legend(auxplot)

# 3 place the legend in the ggpairs grid with putPlot

graph1 <- putPlot(plotwithoutlegend,mylegend,3,4)
show(graph1)

# However  adding a theme modification  makes the legend disappear.

graph2 <- graph1 +theme(strip.background =element_blank(), 
                        strip.placement = "outside")
show(graph2)
@schloerke
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants