这里有一个相当具体的问题,但它可能有助于其他有类似问题的人。
我有一些简单的数据:
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)
更多推荐
发布评论