繁体   English   中英

R plotly x轴使用标签显示

[英]R plotly x-axis use labels for display

尝试使用 R Plotly 绘制条形图。 我需要按 q_order 排序的图表 x 轴,但需要让 x 轴显示来自名为 title 的数据的标签。 我该怎么做?

数据

在此处输入图像描述

图表

在此处输入图像描述

代码

 fig <- plot_ly(
  data = ybq,
  x = ~q_order,
  y = ~t_put,
  type = "bar"
) %>%
  layout(xaxis=list(
               autorange="reversed", 
               type="category"
               ))

您可以根据q_order中的值安排title的因子水平。

library(plotly)

ybq$title <- factor(ybq$title, ybq$title[order(ybq$q_order)])

plot_ly(
  data = ybq,
  x = ~title,
  y = ~q_order,
  type = "bar"
)

在此处输入图像描述

数据

ybq <- data.frame(title = c('21-Jan', 'Q4 2020', 'Q3 2020', 'Q2 2020'), 
                  t_put = c(1606, 11419, 10882, 6525), 
                  q_order = c(112021, 42020,32020, 22020))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM