R 为什么ggplot2会对条形图的值重新排序?

R 为什么ggplot2会对条形图的值重新排序?,r,ggplot2,bar-chart,R,Ggplot2,Bar Chart,我正在使用ggplot2绘制一个简单的条形图,它奇怪地对0值的位置进行了重新排序。以下是代码和图表: x <- c("Oct-Nov","Nov-Dec", "Dec-Jan", "Jan-Feb", "Feb-March") zz <- c(0.6363636, 0.1666667, 0.0000000, -0.2857143 , 0.6666667) qplot(x, zz, geom = "bar", stat = "identity") xggplot正在按字母顺序

我正在使用
ggplot2
绘制一个简单的条形图,它奇怪地对0值的位置进行了重新排序。以下是代码和图表:

x <- c("Oct-Nov","Nov-Dec", "Dec-Jan", "Jan-Feb", "Feb-March")
zz <- c(0.6363636,  0.1666667,  0.0000000, -0.2857143 , 0.6666667)  
qplot(x, zz, geom = "bar", stat = "identity")

xggplot正在按字母顺序对向量排序。若要避免此行为,应在打印前在因子中变换向量

x <- c("Oct-Nov","Nov-Dec", "Dec-Jan", "Jan-Feb", "Feb-March")
x<-factor(x,levels=unique(x))
zz <- c(0.6363636,  0.1666667,  0.1000000, -0.2857143 , 0.6666667)  
qplot(x, zz, geom = "bar", stat = "identity")

默认情况下,
x ggplot2按字母顺序排列。这可能是问题的重复。