本文介绍了Plotly R:当每个 x 因子水平存在两个值时,无法绘制点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
I have a data frame like this:
dput(df)
structure(list(x = structure(c(1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L,
4L, 5L), .Label = c("41197708", "41223094", "41244000", "41244435",
"41244936"), class = "factor"), y = c(1, 1, 1, 1, 1, 2, 2, 2,
2, 2)), .Names = c("x", "y"), row.names = c(NA, -10L), class = "data.frame")
Trying to print a scatter plot with points as follows:
plot_ly(df, x = levels(x), y = y, mode = 'markers')
I only see points corresponding to y = 1 and not y = 2. Any idea why?
The following works in plotly, but then it treats x axis values as numeric / continuous (not what I want):
plot_ly(df, x = x, y = y, mode = 'markers')
解决方案
Isn't this a duplicate of your previous question and related to this github issue ?
If you do:
plot_ly(df, x = x, y = y, mode = "markers") %>%
layout(xaxis = list(type = "category"))
You'll get:
这篇关于Plotly R:当每个 x 因子水平存在两个值时,无法绘制点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!