2013-01-21 52 views
1

數據鏈接繪製多個barplot: https://www.dropbox.com/s/rvwq3uw0p14g9c6/GTAP_Macro.csv使用facet_wrap()

代碼:

 ccmacrosims <- read.csv(file = "F:/Purdue University/RA_Position/PhD_ResearchandDissert/PhD_Draft/GTAP-CGE/GTAP_NewAggDatabase/NewFiles/GTAP_Macro.csv", header=TRUE, sep=",", na.string="NA", dec=".", strip.white=TRUE) 

    ccmacrorsts <- as.data.frame(ccmacrosims) 
    ccmacrorsts[6:10] <- sapply(ccmacrorsts[6:10],as.numeric) 
    ccmacrorsts <- droplevels(ccmacrorsts) 
    ccmacrorsts <- transform(ccmacrorsts,region=factor(region,levels=unique(region))) 

    library(ggplot2) 
    #Data manipulations to select variables of interest within the dataframe 
    GDPtradlib1 <- melt(ccmacrorsts[ccmacrorsts$region %in% c("EAsia","USA","OecdEU","XMidEast","FrmUSSR","EastEU","TUR","MAR"), ]) 
    GDPtradlib2 <- GDPtradlib1[GDPtradlib1$sres %in% c("AVERAGE"), ] 
    GDPtradlib.f <- GDPtradlib2[GDPtradlib2$variable %in% c("GDP"), ] 
    GDPtradlib.f <- subset(GDPtradlib.f, tradlib != "BASEDATA") 

    GDPtradlib.f[1:20,] 

    #Plotting 
    plot <- ggplot(data = GDPtradlib.f, aes(x=factor(tradlib), y=value) + 
    plot + geom_bar(stat="identity") + facet_wrap(~region, scales="free_y") 

問:我想通過tradlib方案(X_AXIS)每個區域繪製變量GDP(Y_AXIS)和使用facet_wrap()來產生多個條形圖。

R-消息錯誤:

+ plot <- ggplot(data = GDPtradlib.f, aes(x=factor(tradlib), y=value) + 
Error: unexpected symbol in: 
"plot + geom_bar(stat="identity") + facet_wrap(~region, scales="free_y") 
plot" 
> plot + geom_bar(stat="identity") + facet_wrap(~region, scales="free_y") 
Error in plot + geom_bar(stat = "identity") : 
    non-numeric argument to binary operator 
+1

你錯過了''' – rrs

回答

4

你缺少一個)y=value)

除此之外,您的代碼的工作,它產生下面的圖片:enter image description here

從您的代碼,我就是跑的代碼唯一的區別,我用gdata庫下降水平。

+0

非常感謝你。 – iouraich