简体   繁体   English

如何在剧情中在标题周围添加填充?

[英]How do I add padding around a title in plotly?

I am converting my ggplot2 graph into plotly. 我正在将ggplot2图转换为plotly。 I'd like to add the title manually, since I want to leave space to add a subtitle afterwards - which ggplotly doesn't do on its own. 我想手动添加标题,因为我想留出空间在事后添加字幕ggplotly不能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()

The docs say that I can set the padding with pad, but when I add it to the layout function, it serves an error saying that it is an invalid argument. 文档说我可以使用pad来设置padding,但是当我将其添加到layout函数中时,会显示错误消息,表明它是无效的参数。

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

The title should be created like shown below. 标题应如下所示创建。

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

Where the title is a list with values text and pad . title是带有值textpad的列表。 Please let me know if this fixes your issue! 如果这可以解决您的问题,请告诉我!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM