Highlighting individual axis labels in bold using ggplot2

后端 未结 3 2034
无人共我
无人共我 2020-12-31 10:58

I want to highlight individual axis labels in bold. I am aware of this answer by @MrFlick but I can\'t figure out how to do this a) for more than one item,

3条回答
  •  情深已故
    2020-12-31 11:50

    You can create a named vector of expressions (that turn text to bold) in scale_x_discrete and use parse=TRUE to evaluate the expressions:

    ggplot(xx, aes(x=CLONE, y=VALUE, fill=YEAR)) + 
        geom_bar(stat="identity", position="dodge") +
        facet_wrap(~TREAT) +
        scale_x_discrete(labels=c("A"=expression(bold(A)), "C"=expression(bold(C)),
                                  "E"=expression(bold(E)), parse=TRUE))
    

    You can probably create the vector of expressions programmatically, rather than typing it out, but the way to do that is escaping me right now.

提交回复
热议问题