如何使用指数(科学)符号打印 p 值?

How to print p-values with exponent (scientific) notation?

当使用 'ggplot' 在 R 中打印值时,我遇到了正确编写指数的问题。请看下面的图,以及我想获得的红色手写内容的示例。

data <- data.frame(var = 1:10,
                  pvalue=c(0.1,0.001,0.0000133233,0.2,0.2222,0.43254,0.1,0.67,0.6777,0.2)) %>% 
  mutate(pvalue=as.character(signif(pvalue,digits=2)))# %>%mutate(pvalue = sub("e","10^",pvalue) )


data %>% 
  ggplot(aes(y = var)) +
  geom_text(aes(x = 0, label = pvalue), parse=T)

如果您只需要将带有e的值更改为指数形式,您只需在注释代码中添加%.%

data <- data.frame(var = 1:10,
                   pvalue = c(0.1,0.001,0.0000133233,0.2,0.2222,
                              0.43254,0.1,0.67,0.6777,0.2)) %>% 
                   mutate(pvalue = as.character(signif(pvalue,digits=2))) %>%
                   mutate(pvalue = sub("e","%.% 10^",pvalue) )
data %>% 
  ggplot(aes(y = var)) +
  geom_text(aes(x = 0, label = pvalue), parse = TRUE)

结果: