0

我正在尝试以 2x2 网格布局排列图表,X 轴为年份,Y 轴为成本。当我按单个图形格式化时,我的格式,即美元符号在那里,但是当我在网格布局中排列它时,美元符号和逗号消失了。

下面的代码:

rat<-qplot(tallc$Group.1,COSTS,data=tallc, geom=c("point","smooth"), 
method="lm",
           xlab= "YEAR",
           ylab= "COST",
           scale_x_continuous(limits = c(1999,2012)),
           main= "Total Costs from 1999 to 2012")      
rat1 <- rat+scale_x_continuous(breaks=c(1999,2000,2001,2002,2003,2004,2005,2006,
           2007,2008,2009,2010,2011,2012))
rat1 + scale_y_continuous(labels=dollar)

我使用的那一刻

pushViewport(viewport(layout = grid.layout(2, 2)))
print(a, vp = viewport(layout.pos.row = 1, layout.pos.col = 1))
print(b, vp = viewport(layout.pos.row = 1, layout.pos.col = 2))
print(c, vp = viewport(layout.pos.row = 2, layout.pos.col = 1))
print(rat1, vp = viewport(layout.pos.row = 2, layout.pos.col = 2))

美元符号消失。

4

1 回答 1

0

以下是一些缺失的项目(和答案):

 tallc<-data.frame(COSTS=rnorm(9), Group=1999:2007)  # fake data
 require(ggplot2) # obvious
 require(scales) # not so obvious
 # first part of code
 ##### The missing step:
 rat1 <- rat1 + scale_y_continuous(labels=dollar)
 require(grid)
 # Second part: grid code
 # success with plotting dollar-scale in lower right corner
 # (despite errors from the missing a,b, and c objects.)

您从未将添加scale_y_continuous带有“美元符号”的结果分配给rat1,因此rat1在仅添加 x 比例后保持在相同的状态。

于 2013-08-17T16:13:21.020 回答