我正在将我的 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
是一个包含值 text
和 pad
的列表。如果这能解决您的问题,请告诉我!
关于r - 如何在标题周围添加填充?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55923832/