使用facet_wrap()绘制多个条形图

时间:2013-01-21 19:52:55

标签: r ggplot2

数据链接: 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") 

问题:我正在尝试为GDP方案(x_axis)为每个区域绘制变量tradlib(y_axis),并使用facet_wrap()生成多个条形图。

R-message错误:

+ 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

0 个答案:

没有答案