How to change the size of legend text in ggplot2?

18,195

Remove label.theme = element_text(angle = 0) from your guides seems to fix this.

guides(color=guide_legend(override.aes=list(shape=c(NA,16, 16, 16, 16),
                                        linetype=c(3,0, 0, 0, 0)),
                      direction = "vertical", title.position = "top",
                      label.position="right", label.hjust = 0, label.vjust = 0.5
                      #,label.theme = element_text(angle = 0)
                      )) +
theme(legend.text=element_text(size=10))

enter image description here

Share:
18,195
shiny
Author by

shiny

Updated on June 14, 2022

Comments

  • shiny
    shiny almost 2 years

    I got this plot using the data and code below

    enter image description here

    I want to be able to change the size of legend text (A, B, M1, ,M3). I tried using

    legend.text=element_text(size=0.5)
    

    but it didn't change. Any suggestion how to reduce the size of legend.text?

    Code

    ggplot(df.trial1, aes(x=Date, y= A, color="A"))+
          geom_line(linetype=3, size=0.2)+
          geom_point(aes(x=Date, y=B, color="B"), shape = 16, size =1, alpha=0.5)+
          geom_point(aes(x=Date, y=Value, color=Method), size =1, alpha=0.5)+
          scale_colour_manual(name=" ", values=cols,
                          labels=c("A", "B", 'M1', "M2", "M3"))+
          scale_linetype_manual(values = c("dashed")) +
          scale_x_date(breaks = date_breaks("1 month"), labels = date_format("%d-%b-%y"))+
      guides(color=guide_legend(override.aes=list(shape=c(NA,16, 16, 16, 16),
                                              linetype=c(3,0, 0, 0, 0)),
                            direction = "vertical", title.position = "top",
                            label.position="right", label.hjust = 0, label.vjust = 0.5,
                            label.theme = element_text(angle = 0)))+
      labs(x=expression(Date), y=expression(Value))+
      theme(legend.text=element_text(size=0.5))
    
  • shiny
    shiny about 8 years
    Perfect. Thank you :-)
  • giordano
    giordano over 6 years
    Why label.theme = element_text(angle = 0) has to be removed? Or: why if I add ylab("blabla") size does not work?