如何使用指数(科学)表示法打印 p 值?

发布于 2025-01-13 00:14:31 字数 554 浏览 0 评论 0原文

当使用“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)

Ggplot

When printing values in R using 'ggplot', I'm facing issues to write the exponent proprerly. See the plot below, and an example of what I would like to obtain hand-written in red.

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)

Ggplot

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南汐寒笙箫 2025-01-20 00:14:31

如果您只需将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)

结果:

“在此处输入图像描述"

If you only need to change the values with e to exponent forms, you only need to add %.% to your commented code.

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)

The result:

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文