r - 刻度线标签中的数学表达式,ggplot2
问题描述
我想使用数学表达式制作刻度线标签。请参见下一个示例:
library(tidyverse)
gl<-30
ggplot(data = data.frame(x = c(-5, 5)), aes(x)) +
stat_function(fun = dt, args = list(df = 30))+ylab("f(t)")+
geom_segment(aes(x=qt(.975,gl),xend=qt(.975,gl),y=0,yend=dt(qt(.975,gl),gl)))+
scale_x_continuous("t", round(c(-5,qt(1-.975,gl),0,qt(.975,gl),5),3), limits=c(-5,5),labels=c("-5.000", "-2.042", "0" ,"list(q[0.95]==0.025)", "5.000"))+
annotate("segment", x = c(2.2), xend = c(3.8),
y = c(0.02), yend = c(.16), colour = "red", size=1, alpha=0.6, arrow=arrow())+
annotate("segment", x = c(-1), xend = c(-3),
y = c(0.02), yend = c(.16), colour = 1, size=1, alpha=0.6, arrow=arrow())+
stat_function(fun = dt, args = list(df = gl),
xlim = c(-5,qt(.975,gl)),
geom = "area",fill="red",alpha=0.5)+
annotate("text", x = c(-3.8,3.8,4), y = c(0.18,0.18,.3),
label = c("1-alpha","alpha/2","list(q[0.95]==0.025)"),parse=T , size=4 , fontface="bold")+
theme_bw()
scale_x_continuous("t", round(c(-5,qt(1-.975,gl),0,qt(.975,gl),5),3), limits=c(-5,5),labels=c("-5.000", "-2.042", "0" ,"list(q[0.95]==0.025)", "5.000"))
被替换为
scale_x_continuous("t", round(c(-5,qt(1-.975,gl),0,qt(.975,gl),5),3), limits=c(-5,5),labels=c("-5.000", "-2.042", "0" ,"list(q[0.95]==0.025)", "5.000"),parse=T)
得到一个错误:
scale_x_continuous("t", round(c(-5, qt(1 - 0.975, gl), 0, qt(0.975, ) 中的错误:未使用的参数 (parse = T)
如何在 scale_x_continuous 中实现数学表达式,就像在 annotate 中实现的那样?
解决方案
推荐阅读
- mysql - 使用 brew mysql.server 安装 mysql@5.6 不是命令
- python - Python Selenium 选择带空格的 div 类
- javascript - Cheerio each() 函数行为异常
- java - Java 嵌套 for 循环(内部 for 循环中带有 if 语句)
- reactjs - React Native:如何将变量放入 require 而不给我一个错误
- javascript - 自动将“/”添加到日期的 Javascript 输入
- amazon-cognito - Congito 用户池的新注册默认为禁用
- javascript - 为演示目的创建站点的副本/会话
- python-3.x - 元组列表中的反转数字
- sqlite - 我们如何在 sqlite 数据库(表)中插入图像?