这个是公众号 小明的数据分析笔记本 2019年8月13号推文
上标代码
library(ggplot2)## Warning: package 'ggplot2' was built under R version 4.0.5
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")下标代码
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")这个是之前的做法
现在有一个R包latex2exp
library(latex2exp)## Warning: package 'latex2exp' was built under R version 4.0.5
#latex2exp_examples(cex=0.8)欢迎关注我的公众号
小明的数据分析笔记本