英文:
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 'empty space' 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("0","1")), map_signif_level=TRUE, textsize = 10.25) +
scale_fill_manual(values = c('#AED6F1', '#F1948A')) + theme_minimal() +
geom_jitter(alpha = 0.8, width = 0.1)+
theme_minimal()+
coord_cartesian(ylim = c(0, max(mtcars$mpg)+5))
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论