R语言与科研

ggplot2绘图添加文本注释上下标问题

2019-08-13  本文已影响0人  小明的数据分析笔记本
问题描述

ggplot2绘图添加注释文本如果想要将其中的数字改为上下标该如何实现?

参考资料

https://stackoverflow.com/questions/7182247/ggplot2-annotate-text-with-superscript

上标代码
library(ggplot2)
df<-data.frame(A=1:5,B=6:10,D=letters[1:5])
ggplot(df,aes(x=A,y=B,color=D))+
  geom_point(size=5)+
  annotate("text",x=3,y=7.5,label="atop(R^2==0.9,Y==X^2+5)",parse=T)+
  theme_bw()+
  theme(legend.position="none")
image.png
下标代码
ggplot(df,aes(x=A,y=B,color=D))+
  geom_point(size=5)+
  annotate("text",x=3,y=8.5,label="X[1]==X[2]",parse=T,color="blue")+
  xlab(expression(X^2))+ylab(expression(Y[1]))+
  theme_bw()+
  theme(legend.position="none")
image.png

欢迎大家关注我的微信公众号小明的数据分析笔记本

公众号二维码.jpg
上一篇下一篇

猜你喜欢

热点阅读