【问题标题】:How to show date every month in plotly?如何在情节中显示每个月的日期?
【发布时间】:2021-12-23 02:57:46
【问题描述】:

我想每 1 个月显示一次日期,但改为每 2 个月显示一次。我也想知道如何将日期(x 轴)倾斜 60 度。这两件事在情节上可能吗?提前致谢。

我的代码:

l <- list(
  font = list(
    family = "sans-serif",
    size = 12,
    color = "#364E6F"),
  bgcolor = "#E4EBF5",
  bordercolor = "#566F92",
  borderwidth = 3)


fig <- plot_ly(sumir_data, x = sumir_data$`Month-year`, y = sumir_data$`Followers-LI`, type = 'bar', name = 'LinkedIn', marker = list(color = '#28EDC4'))
fig <- fig %>% add_trace(y = sumir_data$`EOM Followers Twitter-TW`, name = 'Twitter', marker = list(color = '#00BBFF'))
fig <- fig %>% layout(yaxis = list(title = 'Followers Count',
                                         color = '#364E6F'))
fig <- fig %>% layout(xaxis = list(title = 'Date',
                                         color = '#364E6F'))
fig <- fig %>% layout(legend = l)
fig <- fig %>% layout(paper_bgcolor = '#E4EBF5',
                                              plot_bgcolor = '#E4EBF5')

fig

【问题讨论】:

  • 有趣的问题。您能否提供示例数据或使用具有月/年作为可用字段的公共数据集?

标签: r r-plotly


【解决方案1】:

解决方案是将 dticks = "M1" 添加到 xaxis layout()

我的代码:

l <- list(
  font = list(
    family = "sans-serif",
    size = 12,
    color = "#364E6F"),
  bgcolor = "#FFFFFF",
  bordercolor = "#566F92",
  borderwidth = 3)


fig <- plot_ly(sumir_data, x = sumir_data$`Month-year`, y = sumir_data$`Followers-LI`, type = 'bar', name = 'LinkedIn', marker = list(color = '#28EDC4'))
fig <- fig %>% add_trace(y = sumir_data$`EOM Followers Twitter-TW`, name = 'Twitter', marker = list(color = '#00BBFF'))
fig <- fig %>% layout(yaxis = list(title = 'Number of Followers',
                                         color = '#364E6F'))

fig <- fig %>% layout(xaxis = list(title = 'Date',
                                         color = '#364E6F', dtick = "M1"))
fig <- fig %>% layout(legend = l)
fig <- fig %>% layout(paper_bgcolor = '#FFFFFF',
                                              plot_bgcolor = '#FFFFFF')

fig

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-26
    • 1970-01-01
    • 2021-11-26
    • 1970-01-01
    • 2021-11-23
    • 1970-01-01
    相关资源
    最近更新 更多