[英]R plotly x-axis use labels for display
Trying to use R Plotly to graph bar chart.尝试使用 R Plotly 绘制条形图。 I need the chart x-axis ordered by q_order but need to have the x-axis display the labels from data called title.我需要按 q_order 排序的图表 x 轴,但需要让 x 轴显示来自名为 title 的数据的标签。 How would I do this?我该怎么做?
Data数据
Chart图表
Code代码
fig <- plot_ly(
data = ybq,
x = ~q_order,
y = ~t_put,
type = "bar"
) %>%
layout(xaxis=list(
autorange="reversed",
type="category"
))
You can arrange the factor levels for title
based on values in q_order
.您可以根据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"
)
data数据
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.