Adding "empty space" to perimeter of ggplot2 plot

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

Adding "empty space" to perimeter of ggplot2 plot

问题

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

我有一个看起来像这样的图表:
[初始图表][1]

我尝试使用这段代码来增加星号的大小:

```R
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)

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

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

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


请注意,我已经将代码中的HTML实体字符(如`"`和`'`)翻译为相应的引号。

<details>
<summary>英文:</summary>

I have a figure that looks like this:
[Initial Plot][1]

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)


Unfortunately, this results in the asterisks getting cut off, like so:
[Increased asterisk size][2]

I have tried using `plot.margin` to change the margin sizes, but this is not correct. 

How do I add extra &#39;empty space&#39; around the edges of my plot to prevent this issue?


  [1]: https://i.stack.imgur.com/DFVT5.png
  [2]: https://i.stack.imgur.com/59Gj0.png

</details>


# 答案1
**得分**: 1

One way is to use `coord_cartesian(ylim = c(ymin, ymax))`
```R
使用 `coord_cartesian(ylim = c(ymin, ymax))` 这种方式。
英文:

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

library(ggplot2)
library(ggsignif)

ggplot(mtcars, aes(x = factor(am), y = mpg, fill = factor(am))) + geom_violin(width = 0.5) +
  geom_boxplot(outlier.shape = NA, width = 0.2, coef = 0) + 
  geom_signif(comparisons = list(c(&quot;0&quot;,&quot;1&quot;)), map_signif_level=TRUE, textsize = 10.25) + 
  scale_fill_manual(values = c(&#39;#AED6F1&#39;, &#39;#F1948A&#39;)) + theme_minimal() + 
  geom_jitter(alpha = 0.8, width = 0.1)+
  theme_minimal()+
  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:

确定