a <- matrix(0,2,10)
a[1,] <-c(5.165815, 0.1544952, 1.375914, 0.3414154, 13.78202, 17.34233, 3.58367, 2.33674, -0.1583099, 1.26791)
a[2,] <-c(3.717303, 1.244664, -0.3640652, -1.925349, 3.510475, -0.8143187, 3.871202, 1.268744, -2.367854, -2.794683)
a<-data.frame(a)
colnames(a) <- c("ATL","ORD","LAX","DFW","JFK","EWR","IAH","DTW","MSP","MIA")
spc_data <- c('ASO4IJ','AECIJ')
rownames(a) <- spc_data
library(ggplot2)
library(reshape)
a$species <- spc_data
data_1.m <- melt(a, id.var = 'species')
dat11 <- subset(data_1.m,value >= 0)
dat12 <- subset(data_1.m,value < 0)
p <- ggplot(col = 'rainbow', width = 1) +
geom_bar(data = dat11, aes(x=variable, y=value, fill=species),stat = "identity") +
geom_bar(data = dat12, aes(x=variable, y=value, fill=species),stat = "identity") +
xlab("Airport") +
ylab("mass (ng/m3)")
print(p)
如果我们注释掉geom_bar(data = dat12,aes(x =变量,y = value,fill =种类),stat =&#34; identity&#34;)+
x轴是我想要的顺序,但是,如果我们将其添加回来,x轴将按字母顺序排列。从上一篇文章中,有人告诉我这是一个因素问题,但是,level(dat11 $ variable)级别(dat12 $ variable)和level(data_1.m $ variable)都是相同的 &#34; ATL&#34; &#34; ORD&#34; &#34; LAX&#34; &#34; DFW&#34; &#34; JFK&#34; &#34; EWR&#34; &#34; IAH&#34; &#34; DTW&#34; &#34; MSP&#34; &#34; MIA&#34 ;.我不明白为什么它不遵循级别(dat12 $变量),而是按字母顺序排列?
任何建议?