ggplot2 subscript in x-axis labels(ticks, legend)

 
                          
#==============================
# ggplot2: subscript in x-axis labels(ticks)
rm(list=ls(all=TRUE))
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                          

# from: http://stackoverflow.com/questions/6202667/how-to-use-subscripts-in-ggplot2-legends-r

#==============================
# ggplot2: subscript in y-axis labels
rm(list=ls(all=TRUE))
library(ggplot2)
dat <- data.frame(x = rnorm(100), y = rnorm(100))
ggplot(dat, aes(x=x,y=y)) +
     geom_point() +
     labs(y=expression(Blah[1*d]))

ggplot(dat, aes(x=x,y=y)) +
     geom_point() +
     labs(y=expression(Blah["1d"]))
    
ggplot(dat, aes(x=x,y=y)) +
    geom_point() +
    labs(y=expression(Blah[1*d]*"%"))    
    
# from: http://stackoverflow.com/questions/17334759/subscript-letters-in-ggplot-axis-label
# http://stackoverflow.com/questions/8514478/subscripts-in-xlabels-in-ggplot2
# http://stackoverflow.com/questions/15125628/putting-mathematical-symbols-and-subscripts-mixed-with-regular-letters-in-r-ggpl
# http://www.janeshdevkota.com/blog/using-superscripts-and-subscripts-in-ggplot2/

posted @   emanlee  阅读(2713)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 因为Apifox不支持离线,我果断选择了Apipost!
· 通过 API 将Deepseek响应流式内容输出到前端
历史上的今天:
2009-10-10 DataAdapter的Fill方法的连接是否会自动关闭的测试
点击右上角即可分享
微信分享提示