【问题标题】:Line break with x10^x notation ggplot title带有 x10^x 符号 ggplot 标题的换行符
【发布时间】:2020-11-25 23:55:51
【问题描述】:

通过使用“\n”作为换行符,我能够得到看起来像所附图像的图。但是,问题在于 8.8e-14。期刊要求我将其更改为 8.8x10^14(上标为 14)。但是,这仅在我使用表达式(粘贴)时才有效。但在这种情况下,“\n”不再导致换行。我花了大约 5 个小时通过互联网上的不同解决方案反复试验,但无济于事。有没有人有办法解决吗?提前致谢。

我希望它看起来像什么(除了我希望它改为 8.8x10^14):

下面的作品除了没有换行符(我想在“交互”之前换行)

plot_fun_to_revise = function(x, y) {
  ggplot(data = data_for_median_plots, aes(x = .data[[x]], y = .data[[y]], group = Secretor, linetype = Secretor)) +
    stat_summary(geom = "line", fun.data = median_hilow, size = 0.5) +
    stat_sum_df_all("median_hilow",
                    fun.args = (conf.int = 0.5),
                    linetype = "solid",
                    size = 0.5) +
    theme_classic()


lnnt_plot_median <- plot_fun_to_revise("Timepoint", "LNnT") +
        ylim(0,5000) +
        labs(y = paste("LNnT", "(\u03BCg/mL)"),
             title = expression(paste("Time p = 8.8 x", 10^-14, ", Secretor p = 0.35, Interaction p = 0.51")),
             x = "Time (months postpartum)"

【问题讨论】:

    标签: r ggplot2


    【解决方案1】:

    显然,我没有你的数据来复制绘图本身,但既然这无论如何都是关于标签的,让我们制作一个(基本上)空的绘图:

    lnnt_plot_median <- ggplot(data.frame(x = 1, y = 1), aes(x, y)) + 
                          geom_point() +
                          theme_classic() +
                          theme(text = element_text(face = 2, size = 16),
                                plot.title = element_text(hjust = 0.5))
    

    由于您已经在使用 unicode 转义,我认为这里最简单的做法是对上标 1 和上标 4 使用 unicode 转义:

    lnnt_plot_median +
     labs(y = paste("LNnT", "(\u03BCg/mL)"),
          title = paste("Time p = 8.8 x 10\u00b9\u2074,",
                        "Secretor p = 0.35,\n Interaction p = 0.51"),
          x = "Time (months postpartum)")
    

    【讨论】:

    • 哇,非常感谢!没有意识到有办法用 unicode 做到这一点。我真的很感激!
    • 我确实遇到了一个奇怪的问题——只有底线(交互 p = 0.51)是粗体的。顶行不是粗体。即使函数有主题(文本 = element_text(面 = 2,大小 = 16))。任何想法为什么会这样?
    猜你喜欢
    • 2021-12-05
    • 1970-01-01
    • 2012-05-16
    • 2015-02-25
    • 2022-12-30
    • 1970-01-01
    • 1970-01-01
    • 2015-01-05
    • 1970-01-01
    相关资源
    最近更新 更多