如果我的轴标题被剪裁,我应该在ggplot中调整哪些参数?(What parameters should I adjust in ggplot if my axis titles are being

编程入门 行业动态 更新时间:2024-10-28 12:29:04
如果我的轴标题被剪裁,我应该在ggplot中调整哪些参数?(What parameters should I adjust in ggplot if my axis titles are being clipped?)

这里有一个相当具体的问题,但它可能有助于其他有类似问题的人。

我有一些简单的数据:

Y = c(0.02, 0.03, 0.03, 0.04, 0.05, 0.06, 0.08, 0.09, 0.10, 0.13, 0.17, 0.17, 0.21, 0.22, 0.35, 0.47, 0.51, 0.53, 0.54, 0.65, 0.78) X = c(0.45, 0.26, 0.35, 0.22, 0.37, 0.09, 0.27, 0.51, 0.39, 0.37, 0.37, 0.27, 0.51, 0.36, 0.44, 0.49, 0.63, 0.49, 0.71, 0.56, 0.67) self1 = data.frame(X, Y)

我也有一个简单的自定义ggplot主题:

plot.theme = theme(axis.text = element_text(size=26), axis.title=element_text(size=28), plot.title=element_text(size=36, margin=margin(0,0,20,0)), panel.grid.minor = element_blank(), plot.margin=unit(c(0.1,0.25,0.5,0.85), "cm"), axis.title.y = element_text(margin=margin(0,15,0,0)), panel.border = element_rect(color="black", fill=NA, size=2), axis.ticks = element_blank(), legend.title = element_text(size=26), legend.text = element_text(size=18))

当我用边缘直方图绘制数据的散点图时:

bing = ggplot(self1, aes(x=X, y=Y)) + geom_point(size=3) + geom_smooth(method = "lm", se=F, color="black") + plot.theme + ylab("Observed selfing rate") + xlab("Observed crossing rate") + geom_vline(xintercept = 0.42, linetype="longdash") + geom_hline(yintercept = 0.25, linetype="longdash") ggExtra::ggMarginal(bing, type = "histogram", bins=6, size=10)

一切看起来都很棒,除了“观察到的穿越率”中的“g”在图表的底部被切断。 我已经尝试了我可以想到的每个主题参数的烦躁,我也尝试调整ggMarginal几个参数,但我还没有找到我需要更改的一个以使所有内容保持在绘图区域内。 谁能帮我吗? 我怀疑这个问题最终取决于ggMarginal自动调整各种主题参数大小的方式,但这只是一种预感。

Fairly specific question here, but it may help others who are having similar issues.

I have some simple data:

Y = c(0.02, 0.03, 0.03, 0.04, 0.05, 0.06, 0.08, 0.09, 0.10, 0.13, 0.17, 0.17, 0.21, 0.22, 0.35, 0.47, 0.51, 0.53, 0.54, 0.65, 0.78) X = c(0.45, 0.26, 0.35, 0.22, 0.37, 0.09, 0.27, 0.51, 0.39, 0.37, 0.37, 0.27, 0.51, 0.36, 0.44, 0.49, 0.63, 0.49, 0.71, 0.56, 0.67) self1 = data.frame(X, Y)

I also have a simple custom ggplot theme:

plot.theme = theme(axis.text = element_text(size=26), axis.title=element_text(size=28), plot.title=element_text(size=36, margin=margin(0,0,20,0)), panel.grid.minor = element_blank(), plot.margin=unit(c(0.1,0.25,0.5,0.85), "cm"), axis.title.y = element_text(margin=margin(0,15,0,0)), panel.border = element_rect(color="black", fill=NA, size=2), axis.ticks = element_blank(), legend.title = element_text(size=26), legend.text = element_text(size=18))

When I plot a scatterplot of the data with marginal histograms:

bing = ggplot(self1, aes(x=X, y=Y)) + geom_point(size=3) + geom_smooth(method = "lm", se=F, color="black") + plot.theme + ylab("Observed selfing rate") + xlab("Observed crossing rate") + geom_vline(xintercept = 0.42, linetype="longdash") + geom_hline(yintercept = 0.25, linetype="longdash") ggExtra::ggMarginal(bing, type = "histogram", bins=6, size=10)

Everything looks great, except that the "g" in "Observed crossing rate" is getting cut off at the bottom of the graph. I have tried fidgeting with every theme parameter I can think of, and I've also tried adjusting several of the arguments to ggMarginal, but I have yet to find the one I need to change to get everything to stay inside the plot area. Can anyone help me out? I suspect the issue ultimately lies with the way ggMarginal is auto-adjusting the sizes of various theme parameters, but that's just a hunch.

最满意答案

如果g是你的情节,你可以在绘制之前做g$vp = grid::viewport(height=0.9, width=0.9) (print或grid.draw)

if g is your plot, you can do g$vp = grid::viewport(height=0.9, width=0.9) before drawing it (print or grid.draw)

更多推荐

本文发布于:2023-08-05 05:20:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1427661.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:剪裁   参数   标题   ggplot   parameters

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!