当使用ggplot2进行绘图并尝试根据data.frame中的数值变量重新排列因子时,我总是会遇到此问题。通过数字变量重新排序因子
structure(list(Team = structure(1:32, .Label = c("ARI", "ATL",
"BAL", "BUF", "CAR", "CHI", "CIN", "CLE", "DAL", "DEN", "DET",
"GB", "HOU", "IND", "JAC", "KC", "MIA", "MIN", "NE", "NO", "NYG",
"NYJ", "OAK", "PHI", "PIT", "SD", "SEA", "SF", "STL", "TB", "TEN",
"WAS"), class = "factor"), Fans = c(49L, 145L, 175L, 75L, 104L,
167L, 101L, 147L, 157L, 304L, 112L, 338L, 200L, 118L, 37L, 60L,
65L, 225L, 371L, 97L, 163L, 87L, 84L, 102L, 111L, 85L, 422L,
311L, 63L, 56L, 49L, 271L)), .Names = c("Team", "Fans"), row.names = c(NA,
-32L), class = "data.frame")
这并不由#的球迷重新排序队:
ggplot(total.fans, aes(x=reorder(Team, Fans), y=Fans)) + geom_bar()
而这种转换调用不会改变任何数据:
transform(total.fans, variable=reorder(Team, -Fans))
我缺少什么?
感谢这个工作,我会接受解决方案,但仍然试图找出其他答案出了什么问题。 – tcash21