Ordering in r plotly barchart

后端 未结 3 1461
夕颜
夕颜 2020-12-05 18:03

Why do I get the different order in plotly bar chart than I defined in x and y variables.

E.g.

library(plotly)

plot_ly(
  x = c(\"giraffes\", \"oran         


        
3条回答
  •  北海茫月
    2020-12-05 18:54

    You can also use reorder if you want to order based on a second variable:

    library(plotly)
     x <- c("giraffes", "orangutans", "monkeys")
     y <- c(20, 14, 23)
    
    plot_ly(
      x = ~reorder(x,y),
      y = ~y,
      name = "SF Zoo",
      type = "bar"
      ) 
    

提交回复
热议问题