Changing format of some axis labels in ggplot2 according to condition

前端 未结 1 1759
-上瘾入骨i
-上瘾入骨i 2020-12-06 06:08

I have a ggplot and I want to highlight only some specific x-axis labels according to a predefined condition.

I know that axis text is controlled by



        
相关标签:
1条回答
  • 2020-12-06 06:40

    You can include for example ifelse() function inside element_text() to have different labels.

    ggplot(iris,aes(Species,Petal.Length))+geom_boxplot()+
      theme(axis.text.x=
              element_text(face=ifelse(levels(iris$Species)=="setosa","bold","italic")))
    

    Or you can provide vector of values inside element_text() the same length as number of levels.

    ggplot(iris,aes(Species,Petal.Length))+geom_boxplot()+
     theme(axis.text.x = element_text(face=c("bold","italic","bold"),
                                       size=c(11,12,13)))
    

    enter image description here

    0 讨论(0)
提交回复
热议问题