r - 如何在标题周围添加填充?

标签 r ggplot2 plotly

我正在将我的 ggplot2 图转换为 plotly。我想手动添加标题,因为我想留出空间以便之后添加副标题 - ggplotly 本身不会这样做。

g <- retention_cohorts %>% 
  ggplot(aes(relative_week, round(percent,2), label=relative_week)) + 
  geom_line() +
  scale_y_continuous(labels = percent) +
  scale_x_continuous(breaks = seq(1,24,4),
                     labels = seq(1,6)
  ) +
  geom_text(nudge_y = .02) +
  # geom_text_repel() +
  labs(
    # title = "Purchasing Retention Analysis",
    subtitle = "Customers who order at least one item each week",
    y = "Ratio of Customers",
    x = "Relative Month"
  ) + theme_light()

docs说我可以用 pad 设置填充,但是当我将它添加到 layout 函数时,它会报错说它是一个无效参数。

ggplotly(g) %>%    
  layout(
    title = "My Title",
    pad = list(b = 90, l = 130, r = 50 ))

最佳答案

标题应如下所示创建。

library(plotly)
p <- plot_ly(midwest, x = ~percollege, color = ~state, type = "box")%>%    
  layout(title = list(text = "My Title",pad = list(b = 90, l = 130, r = 50 )))
p

title 是一个包含值 textpad 的列表。如果这能解决您的问题,请告诉我!

关于r - 如何在标题周围添加填充?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55923832/

相关文章:

r - 使用 ggplot2 和分组变量创建圆环图

R:在列表中保存 ggplot2 图

r - 无法更改 ggplot2 中的图例

python - 在Python中以绘图方式勾勒出绘图区域

r - 在 data.frame 上分配(不同的)列类

r - 线条下方的3D填充

r - 如何在其他脚本中包含(源)R 脚本

r - 为什么 ggplot annotate 会抛出此警告 : In is. na(x) : is. na() 应用于 'expression' 类型的非(列表或向量)

python - Heroku 部署 : dash. 异常。NoLayoutException

python - Plotly:如何设置分组子图?