Plotly中的源注释

时间:2017-04-23 00:03:31

标签: r plotly

有没有办法在Plotly的x轴标签下插入源注释?我可以在x轴下面得到一个注释,但如果我改变了边距,注释就会被切断。现在,我可以在x轴和x轴标签之间添加注释。下面是包含图表的MWE。

df <- data.frame(x = 1:10, y = 1:10)
plot_ly(data = df, x = ~x, y = ~y, type = 'scatter', mode = 'lines') %>%
  layout(title = 'Sample Chart',
         margin = list(l = 50, r = 50, t = 60, b = 60),
         annotations = list(text = 'Source: U.S. Census Bureau.',
                            font = list(size = 12),
                            showarrow = FALSE,
                            xref = 'paper', x = -0.03,
                            yref = 'paper', y = -0.2))

enter image description here

我想移动&#34;来源:美国人口普查局&#34;在x轴标题下面。

1 个答案:

答案 0 :(得分:1)

您需要使用html标记添加换行符

plot_ly(data = df, x = ~x, y = ~y, type = 'scatter', mode = 'lines') %>%
+     layout(title = 'Sample Chart',xaxis=list(
+         title = 'x <br> Source: U.S. Census Bureau.'),
+            margin = list(l = 50, r = 50, t = 60, b = 60))