how to use a numeric variable as character in plot_ly r graphs -
i quite new plotly basic question, have simple data frame :
id = c("01","02","03","04","05") value = c(1:5) data=data.frame(id,value)
when plot using plot_ly :
require(plotly) plot_ly(data,x=id,y=value)
plot_ly think id variable numeric variable, on x axis, graduation 1, 1.5, 2, 2.5 ... makes no sense.
if want plot_ly understand variable character, have add non-numeric character :
data$id = paste0("n",id) plot_ly(data,x=id,y=value)
this code gives me want, whith disgracious "n" before id.
any ideas ?
useless have no problem using ggplot.
based on github issue 1 needs explicitly specify axis type.
hope helps. disregard misinformed comment earlier.
library(plotly) df <- data.frame(x = c("a", "b", "c"), y = 1:3) # works fine plot_ly(df, x = x, y = y, mode = "markers") # treated numeric df <- data.frame(x = c("1000", "2000", "3000"), y = 1:3) plot_ly(df, x = x, y = y, mode = "markers") # force categorical axis plot_ly(df, x = x, y = y, mode = "markers") %>% layout(xaxis = list(type = "category")) # treated categorical df <- data.frame(x = c("1000a", "2000b", "3000c"), y = 1:3) plot_ly(df, x = x, y = y, mode = "markers")
Comments
Post a Comment