在ggqqplot(ggpubr/ggpar)轴上添加斜体delta和上标。

huangapple go评论162阅读模式
英文:

Adding italic delta and superscript in ggqqplot (ggpubr/ggpar) axis

问题

我正在制作我的数据的 qq 图,并找到了 ggqqplot 这个函数,它可以添加线条和置信区间。我的数据是稳定同位素数据,我希望 y 轴标签显示为:样本 δ<sup>13</sup>C 值。

由于只涉及标签,数据集并不重要 - 从网上找到的

  1. # 创建一些数据
  2. set.seed(1234)
  3. wdata = data.frame(
  4. sex = factor(rep(c("F", "M"), each=200)),
  5. weight = c(rnorm(200, 55), rnorm(200, 58)))
  6. head(wdata, 4)
  7. # 没有斜体和上标
  8. ggqqplot(wdata,
  9. x = "weight",
  10. title = NULL,
  11. xlab = NULL,
  12. ylab = "样本 δ13C 值"
  13. )
  14. # 尝试使用 bquote 和 ^ 添加上标 - unicode 未被识别,尝试使用 delta
  15. # https://stackoverflow.com/questions/63010394/superscript-in-axis-labels-in-ggplot2-for-ions
  16. # 产生错误:Error in `map()`: ℹ In index: 5. ℹ With name: ylab. Caused by error in `.f()`: ! argument "user_env" is missing, with no default
  17. ggqqplot(wdata,
  18. x = "weight",
  19. title = NULL,
  20. xlab = NULL,
  21. ylab = bquote("样本"~delta^{13}*"C 值")
  22. )
  23. # 尝试使用 expression 和 ^ 添加上标 -> 产生错误:unexpected '^'
  24. # (https://stackoverflow.com/questions/69212413/super-script-within-axis-label-using-ggplot2-or-ggpubr)
  25. ggqqplot(wdata,
  26. x = "weight",
  27. title = NULL,
  28. xlab = NULL,
  29. ylab = expression("样本 δ"*^13*"C 值")
  30. )
  31. # 尝试获取普通和斜体文本
  32. # https://stackoverflow.com/questions/72538196/r-ggpubr-ggplot2-use-italics-for-one-factor-level
  33. # 产生错误:Error in `map()`: ℹ In index: 5. ℹ With name: ylab. Caused by error in `.f()`: ! argument "user_env" is missing, with no default
  34. ggqqplot(wdata,
  35. x = "weight",
  36. title = NULL,
  37. xlab = NULL,
  38. ylab = expression(plain("样本")~italic("δ")~plain("13C 值"))
  39. )
  40. # 尝试使用 bquote 和 ylab 作为向量
  41. # https://stackoverflow.com/questions/4973898/combining-paste-and-expression-functions-in-plot-labels
  42. # 产生错误:Error in `map()`: ℹ In index: 5. ℹ With name: ylab. Caused by error in `.f()`: ! argument "user_env" is missing, with no default
  43. ylab <- bquote("样本"~delta^13*"C 值")
  44. ggqqplot(wdata,
  45. x = "weight",
  46. title = NULL,
  47. xlab = NULL,
  48. ylab = ylab
  49. )

希望这些信息对你有帮助!

英文:

I am making qq plots of my data and found ggqqplot, which adds the line and the confidence intervals. I have stable isotope data and ultimately want my y-axis label to show: Sample δ<sup>13</sup>C Values.

since just working with the label, dataset does not matter - got this off the web

  1. # Create some data
  2. set.seed(1234)
  3. wdata = data.frame(
  4. sex = factor(rep(c(&quot;F&quot;, &quot;M&quot;), each=200)),
  5. weight = c(rnorm(200, 55), rnorm(200, 58)))
  6. head(wdata, 4)
  7. # no italics no superscript
  8. ggqqplot(wdata,
  9. x = &quot;weight&quot;,
  10. title = NULL,
  11. xlab = NULL,
  12. ylab = &quot;Sample \u03B413C Values&quot;
  13. )
  14. #tried bquote with ^ for superscript -unicode not recognized, tried delta
  15. #https://stackoverflow.com/questions/63010394/superscript-in-axis-labels-in-ggplot2-for-ions
  16. #produces Error in `map()`: ℹ In index: 5. ℹ With name: ylab. Caused by error in `.f()`: ! argument &quot;user_env&quot; is missing, with no default
  17. ggqqplot(wdata,
  18. x = &quot;weight&quot;,
  19. title = NULL,
  20. xlab = NULL,
  21. ylab = bquote(&quot;Sample&quot;~delta^{13}*&quot;C Values&quot;))
  22. # tried expression with ^ for superscript -&gt; produces error unexpected &#39;^&#39;
  23. #(https://stackoverflow.com/questions/69212413/super-script-within-axis-label-using-ggplot2-or-ggpubr)
  24. ggqqplot(wdata,
  25. x = &quot;weight&quot;,
  26. title = NULL,
  27. xlab = NULL,
  28. ylab = expression(&quot;Sample \u03B4&quot;*^13*&quot;C Values&quot;)
  29. )
  30. #tried just getting plain and italic text
  31. #https://stackoverflow.com/questions/72538196/r-ggpubr-ggplot2-use-italics-for-one-factor-level
  32. #produces Error in `map()`: ℹ In index: 5. ℹ With name: ylab. Caused by error in `.f()`: ! argument &quot;user_env&quot; is missing, with no default
  33. ggqqplot(wdata,
  34. x = &quot;weight&quot;,
  35. title = NULL,
  36. xlab = NULL,
  37. ylab = expression(plain(&quot;Sample&quot;)~italic(&quot;\u03B4&quot;)~plain(&quot;13C Values&quot;))
  38. )
  39. #tried using bquote and ylab as vector
  40. #https://stackoverflow.com/questions/4973898/combining-paste-and-expression-functions-in-plot-labels
  41. #produces Error in `map()`: ℹ In index: 5. ℹ With name: ylab. Caused by error in `.f()`: ! argument &quot;user_env&quot; is missing, with no default
  42. ylab &lt;- bquote(&quot;Sample&quot;~delta^13*&quot;C Values&quot;)
  43. ggqqplot(wdata,
  44. x = &quot;weight&quot;,
  45. title = NULL,
  46. xlab = NULL,
  47. ylab = ylab
  48. )

答案1

得分: 3

你可以使用ggplot2::labs()函数来添加y轴标签,而不是使用ylab参数:

  1. library(ggpubr)
  2. ggqqplot(wdata,
  3. x = "weight",
  4. title = NULL,
  5. xlab = NULL
  6. ) +
  7. labs(y = bquote("Sample"~delta^{13}* "C Values"))

在ggqqplot(ggpubr/ggpar)轴上添加斜体delta和上标。

英文:

Instead of using the ylab argument you could add your y axis label with ggplot2::labs():

  1. library(ggpubr)
  2. ggqqplot(wdata,
  3. x = &quot;weight&quot;,
  4. title = NULL,
  5. xlab = NULL
  6. ) +
  7. labs(y = bquote(&quot;Sample&quot;~delta^{13}*&quot;C Values&quot;))

在ggqqplot(ggpubr/ggpar)轴上添加斜体delta和上标。

答案2

得分: 3

stefan比我快了1分钟。
我发布我的答案,因为它使用了expression而不是bquote。但是主要的技巧是相同的,先创建没有ylab的图,然后添加y轴标签。

  1. # 创建一些数据
  2. set.seed(1234)
  3. wdata = data.frame(
  4. sex = factor(rep(c("F", "M"), each=200)),
  5. weight = c(rnorm(200, 55), rnorm(200, 58)))
  6. library(ggpubr)
  7. #&gt; 加载需要的包: ggplot2
  8. g <- ggqqplot(wdata,
  9. x = "weight",
  10. title = NULL,
  11. xlab = NULL)
  12. g + labs(y = expression(Sample~delta^{13}*C~Values))

在ggqqplot(ggpubr/ggpar)轴上添加斜体delta和上标。<!-- -->

使用 reprex v2.0.2 在2023-08-08创建

英文:

stefan beat me by 1 minute.
I post my answer because it uses expression, not bquote. But the main trick is the same, create the plot without ylab, then add the y-axis label to it.

  1. # Create some data
  2. set.seed(1234)
  3. wdata = data.frame(
  4. sex = factor(rep(c(&quot;F&quot;, &quot;M&quot;), each=200)),
  5. weight = c(rnorm(200, 55), rnorm(200, 58)))
  6. library(ggpubr)
  7. #&gt; Loading required package: ggplot2
  8. g &lt;- ggqqplot(wdata,
  9. x = &quot;weight&quot;,
  10. title = NULL,
  11. xlab = NULL)
  12. g + labs(y = expression(Sample~delta^{13}*C~Values))

在ggqqplot(ggpubr/ggpar)轴上添加斜体delta和上标。<!-- -->

<sup>Created on 2023-08-08 with reprex v2.0.2</sup>

huangapple
  • 本文由 发表于 2023年8月9日 04:24:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/76862977.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定