我有以下数据框:
structure(list(Var1 = structure(1:7, .Label = c("Friday", "Monday",
"Saturday", "Sunday", "Thursday", "Tuesday", "Wednesday"), class = "factor"),
Freq = c(20938L, 43147L, 35027L, 24087L, 7148L, 6310L, 19027L
)), .Names = c("Var1", "Freq"), row.names = c(NA, -7L), class = "data.frame")
看起来像这样:
Var1 Freq
1 Friday 20938
2 Monday 43147
3 Saturday 35027
4 Sunday 24087
5 Thursday 7148
6 Tuesday 6310
7 Wednesday 19027
当我使用绘图库绘制它时,x轴从星期三开始,一直到星期五。但是我想从周日到周六重新排序标签。我使用以下代码:
假设't'是上面给出数据的数据框:
target <- c("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")
a <- t[match(target, t$Dayoftheweek), ]
plot_ly(a, x = Dayoftheweek, y = Freq, type = "bar", color = Dayoftheweek)
这不起作用。我已将rownames重置为null仍然会出现同样的问题。