【问题标题】:Left-align chart title in plotly在 plotly 中左对齐图表标题
【发布时间】:2017-11-26 12:24:26
【问题描述】:

如何在plot_ly 对象(从ggplotly 创建)中左对齐图表标题?

library(ggplot2)
library(plotly)

p <-
  ggplot(mtcars, aes(mpg, cyl)) + 
  geom_point() + 
  ggtitle("My Title") + 
  # Not necessary by default:
  theme(plot.title = element_text(hjust = 0.0))

p

ggplotly(p)

p 的输出(预期的标题对齐):

ggplotly(p)(标题对齐未保留):

【问题讨论】:

    标签: r ggplot2 plotly


    【解决方案1】:

    plot_lyadded 这个功能。现在你可以打电话了:

    ggplotly(p) %>%
      layout(
        title = list(
          xanchor = "right"
        )
      )
    

    ggplotly(p) %>%
      layout(
        title = list(
          x = 0.1
        )
      )
    

    其中x 是标准化位置,x=0 一直位于左侧,x=1 一直位于右侧。

    【讨论】:

      【解决方案2】:

      你可以的

      ggplotly(p) %>%
        add_annotations(
          yref="paper", 
          xref="paper", 
          y=1.15, 
          x=0, 
          text="My Title", 
          showarrow=F, 
          font=list(size=17)
        ) %>% 
        layout(title=FALSE)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-01-22
        • 1970-01-01
        • 2015-07-18
        • 1970-01-01
        • 2021-02-18
        • 2013-09-07
        • 2019-10-01
        • 2015-03-22
        相关资源
        最近更新 更多