How to use subscripts in ggplot2 legends [R]

前端 未结 2 1594
迷失自我
迷失自我 2020-12-03 10:03

Can I use subscripts in ggplot2 legends? I see this question on greek letters in legends and elsewhere, but I can\'t figure out how to adapt it.

I thought that using

2条回答
  •  無奈伤痛
    2020-12-03 10:45

    If you want to incorporate Greek symbols etc. into the major tick labels, use an unevaluated expression.

    For a bar graph, i did the following:

    library(ggplot2)
    data <- data.frame(names=tolower(LETTERS[1:4]),mean_p=runif(4))
    
    p <- ggplot(data,aes(x=names,y=mean_p))
    p <- p + geom_bar(colour="black",fill="white")
    p <- p + xlab("expressions") + scale_y_continuous(expression(paste("Wacky Data")))
    p <- p + scale_x_discrete(labels=c(a=expression(paste(Delta^2)),
                                   b=expression(paste(q^n)),
                                   c=expression(log(z)),
                                   d=expression(paste(omega / (x + 13)^2))))
    p
    

    barplot with greek letters and superscripts

提交回复
热议问题