How to collect legend into one column in ggplot2
1
0
Entering edit mode
2.7 years ago
Ne ▴ 10

my code look like this;

ggplot(data=my_data, aes(x=samples, y=relative_abundance, fill=species.Name)) + geom_bar(position = "fill",stat = "identity")
+   scale_fill_manual(name=NULL, values = cols) +
          labs(x = NULL,
               y = "Relative Abundance")+
          theme_classic()+
            theme(legend.text = element_text(face = "italic"),
                  legend.key.size = unit(10, "pt"),
                  legend.background = element_rect(fill="lightgray"))+ guides(color=guide_legend(ncol =1))

and I want to collect legend into one column, I tried to add this line in my code but it did not work.

guides(color=guide_legend(ncol =1))

ggplot R barplot • 7.9k views
ADD COMMENT
2
Entering edit mode
2.7 years ago

The legend is for the fill, not color aesthetic, so you need to change it to guides(fill=guide_legend(ncol =1)). Color would be the outline for the boxes.

ADD COMMENT
0
Entering edit mode

Thanks a lot, it works )

ADD REPLY

Login before adding your answer.

Traffic: 809 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6