我正在将我的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 ))
答案 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
是具有值text
和pad
的列表。请告诉我是否可以解决您的问题!