3

数据链接: https ://www.dropbox.com/s/rvwq3uw0p14g9c6/GTAP_Macro.csv

代码:

     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") 

问题:我正在尝试按场景(x_axis)为每个区域绘制变量GDP(y_axis)并用于生成多个条形图。tradlibfacet_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
4

1 回答 1

5

你缺少一个)after y=value)

除了您的代码有效之外,它还生成了以下图像:在此处输入图像描述

与您的代码和我运行的代码的唯一区别是,我使用gdata库来降低关卡。

于 2013-01-21T22:01:21.547 回答