r - 如何防止x轴与facet_wrap(~variable)重叠ggplotly

标签 r ggplot2 plotly

我有一些数据在用 ggpglot 绘制时看起来不错,但 x 轴和下面的图在 plotly::ggplotly() 中重叠。

library(gapminder)
library(plotly)
p <- ggplot(gapminder, aes(x=gdpPercap, y=lifeExp)) + geom_point() + scale_x_log10()
p <- p + aes(color=continent) + facet_wrap(~year,scale="free")
gp <- ggplotly(p)
gp

所以我一直在尝试这个:R: ggplot and plotly axis margin won't change

基本上,我需要增加每个图形对象与下面的图形对象之间的空白。任何想法将不胜感激。

enter image description here

最佳答案

您可以使用以下方法在面之间添加垂直空间:

theme(panel.spacing.y = unit(1, "line"))   # adjust to taste

但是,在转换为绘图时,存在与轴标题和构面相关的障碍,其中轴标题成为注释,需要更多手动移动。

请参阅这些链接了解如何操作:

https://stackoverflow.com/a/47228372/6851825

Converting ggplot object to plotly object creates axis title that overlaps tick values

https://github.com/ropensci/plotly/issues/1224

关于r - 如何防止x轴与facet_wrap(~variable)重叠ggplotly,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66604523/

相关文章:

r - 使用R//redux向redis传输数据

r - 为什么我的用于过滤数据的 R 代码会产生不同的结果 "fread()"和 "ffdf()"?

r - 带有数据框列的 ggplot

python - 如何在 Dash 中创建按钮以从系列中排除值

plotly - 如何在plotly.js图表​​中添加彩色背景栏

r - 编写自己的 tidyselect 函数

r - 子集 data.frame 并计算频率

r - 使用 ggsave 和 Rscript 时如何阻止 R 创建空的 Rplots.pdf 文件

r - 使用 r 缩放水平和垂直线/刻度图( map )

python - Plotly:将自定义文本添加到 px.Treemap 视觉