X-Axis Unwanted Sorting in a Scatter Graph

Hello,

I tried for hours, but I could not succeed. My data frame is simply

df <- as.data.frame(matrix(c(“g”,“d”,“a”,“b”,“z”,5,4,3,2,1),5,2))

library(“plotly”)
p <- plot_ly(data = df,x = ~V1,y = ~V2,type = “scatter”,mode = “lines+markers”) %>%
layout(title = “my title”)
p

So, this give me

But I don’t want x axis to be sorted alphabetically, I just want to keep the order as it is and see a decreasing graph.

Kind regards,

Hey,

This is a more general R problem. Try the factor-function:
V11 <- factor(V1, levels = c(“g”, “d”, “a”, “b”, “z”))
Hope this works.
Cheers,
J.