如何在R中将数字设置为x轴

时间:2017-09-10 12:35:37

标签: r plotly

我想制作条形图并尝试将这些数字添加为x轴,但它会使项目10和'> 10':

脱臼
plot_ly(x = c(1, 2,3,4,5,6,7,8,9,10,'>10'),
        y = c(5, 11, 23,14,21,18,20,19,12,31,21),
        name = "dd",
        type = "bar", 
        xaxis = list(title ="tr"), 
        yaxis = list(title = "cc")) 

我得到以下图表:

enter image description here

1 个答案:

答案 0 :(得分:4)

指定xaxis的布局对我有用:

plot_ly(x = c(1, 2,3,4,5,6,7,8,9,10,'>10'),
        y = c(5, 11, 23,14,21,18,20,19,12,31,21),
        name = "dd",
        type = "bar", 
        xaxis = list(title ="tr"), 
        yaxis = list(title = "cc")) %>%
  layout(title = "Features",
         xaxis = list(type = "category",
                      title = "tr"),
         yaxis = list(title = "cc"))

plotly v2