ggplots上的数学表达式

时间:2018-08-14 18:16:51

标签: r ggplot2

我想表达一下

a x b ^ .5 x c ^ .8

在ggplot标签上

代码如下:

library(latex2exp)

    df = data.frame(x= 1:5,y = 1:5)
    ggplot(df,aes( x= x ,y = y))+geom_point()+
      geom_text(x = 1 , y =1, label = TeX('$ a \\times b^.5 \\times c^.8$'))

知道怎么做吗?

1 个答案:

答案 0 :(得分:1)

library(latex2exp)
library(ggplot2)
library(dplyr)


tex_var <- '$ a \\times b^.5 \\times c^.8$'

# to label each point with the LaTEX expression
df = data.frame(x= 1:5,y = 1:5, z = )
ggplot(df,aes( x= x ,y = y)) +
  geom_point() +
  geom_text(aes( y = y+.25),label = TeX(tex_var, "text"))


# to put it as a label to the whole plot
ggplot(df,aes( x= x ,y = y)) + 
  geom_point() +
  labs(title = TeX(tex_var, "text")) +
  theme(plot.title=element_text(size=20, face="bold", color="red"))

enter image description here enter image description here

相关问题