Reputation: 33
Legends in two ggplot graphs in grid.arrange() are overlapping. I have used legend.positon = "top" or "bottom", another problem arises i.e the ggplot is not showing complete legends. Actually, my legends are quite long. How can get legends printed in two lines to avoid above-mentioned problem?
I have tried legend.position = "top", also legend.box = "vertical" but nothing worked
k1 %>%
ggplot(aes(Alert,Sum, fill = Alert)) +
geom_bar(stat = "identity") +
facet_wrap(~ Model , nrow= 5) +
coord_flip() +
geom_text(aes(label = Sum), fontface = "bold") +
theme(legend.position = "none")+
ggtitle("MODEL WISE ALERT COUNT")+
theme_grey(base_size = 22)+
theme(legend.position = "top")
Upvotes: 2
Views: 395
Reputation: 33
I have found the answer.
k1 %>% ggplot(aes(Alert,Sum, fill = Alert)) + geom_bar(stat = "identity") + facet_wrap(~ Model , nrow= 5) + coord_flip() + geom_text(aes(label = Sum), fontface = "bold") + ggtitle("MODEL WISE ALERT COUNT")+ theme_grey(base_size = 22)+theme(legend.position = "bottom") **+ guides(fill=guide_legend(nrow=2,byrow=TRUE))
Upvotes: 1