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

时间:2019-04-30 15:05:54

标签: r ggplot2 plotly

我正在将我的ggplot2图转换成图。我想手动添加标题,因为我想留出空间来在其后添加字幕-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 ))

1 个答案:

答案 0 :(得分:1)

标题应如下所示创建。

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的列表。请告诉我是否可以解决您的问题!