Adding "empty space" to perimeter of ggplot2 plot

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

Adding "empty space" to perimeter of ggplot2 plot

问题

抱歉,我明白你只需要翻译代码部分。以下是代码的翻译:

  1. 我有一个看起来像这样的图表:
  2. [初始图表][1]
  3. 我尝试使用这段代码来增加星号的大小:
  4. ```R
  5. ggplot(data, aes(x = Cohort, y = C1M_HP, fill = Cohort)) + geom_violin(width = 0.5) +
  6. geom_boxplot(outlier.shape = NA, width = 0.2, coef = 0) +
  7. geom_signif(comparisons = list(c("Control","Dup")), map_signif_level=TRUE, textsize = 6.25) +
  8. scale_fill_manual(values = c('#AED6F1', '#F1948A')) + theme_minimal() +
  9. geom_jitter(alpha = 0.8, width = 0.1)

不幸的是,这导致星号被切割,如下所示:
[增大星号的大小][2]

我尝试使用plot.margin来更改边距大小,但这并不正确。

我该如何在我的图表边缘添加额外的'空白空间'以防止这个问题?

  1. 请注意,我已经将代码中的HTML实体字符(如`"``'`)翻译为相应的引号。
  2. <details>
  3. <summary>英文:</summary>
  4. I have a figure that looks like this:
  5. [Initial Plot][1]
  6. I am trying to increase the size of the asterisks, using this code:

ggplot(data, aes(x = Cohort, y = C1M_HP, fill = Cohort)) + geom_violin(width = 0.5) +
geom_boxplot(outlier.shape = NA, width = 0.2, coef = 0) +
geom_signif(comparisons = list(c("Control","Dup")), map_signif_level=TRUE, textsize = 6.25) +
scale_fill_manual(values = c('#AED6F1', '#F1948A')) + theme_minimal() +
geom_jitter(alpha = 0.8, width = 0.1)

  1. Unfortunately, this results in the asterisks getting cut off, like so:
  2. [Increased asterisk size][2]
  3. I have tried using `plot.margin` to change the margin sizes, but this is not correct.
  4. How do I add extra &#39;empty space&#39; around the edges of my plot to prevent this issue?
  5. [1]: https://i.stack.imgur.com/DFVT5.png
  6. [2]: https://i.stack.imgur.com/59Gj0.png
  7. </details>
  8. # 答案1
  9. **得分**: 1
  10. One way is to use `coord_cartesian(ylim = c(ymin, ymax))`
  11. ```R
  12. 使用 `coord_cartesian(ylim = c(ymin, ymax))` 这种方式。
英文:

One way is to use coord_cartesian(ylim = c(ymin, ymax))

  1. library(ggplot2)
  2. library(ggsignif)
  3. ggplot(mtcars, aes(x = factor(am), y = mpg, fill = factor(am))) + geom_violin(width = 0.5) +
  4. geom_boxplot(outlier.shape = NA, width = 0.2, coef = 0) +
  5. geom_signif(comparisons = list(c(&quot;0&quot;,&quot;1&quot;)), map_signif_level=TRUE, textsize = 10.25) +
  6. scale_fill_manual(values = c(&#39;#AED6F1&#39;, &#39;#F1948A&#39;)) + theme_minimal() +
  7. geom_jitter(alpha = 0.8, width = 0.1)+
  8. theme_minimal()+
  9. coord_cartesian(ylim = c(0, max(mtcars$mpg)+5))

Adding "empty space" to perimeter of ggplot2 plot

huangapple
  • 本文由 发表于 2023年5月13日 22:33:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/76243245.html
匿名

发表评论

匿名网友

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

确定