使用knitr时ggplot2图例和轴没有调整大小

时间:2013-07-01 21:07:54

标签: r ggplot2 knitr

我试图在knitr文档中将两个ggplots彼此相邻。通过使用在线显示的块选项,我能够将它们彼此相邻。但是,当我这样做时,图例和轴标签没有调整大小。他们被切断了,并且比情节大得多。我确信我遗失了一些东西,但我不知道它是什么。

以下是产生问题的最小示例。

\documentclass{article}

\begin{document}

<<data, echo=FALSE>>=
library(ggplot2)
School<-c("a","a","a","a","a","a","b","b","b","b","b","b")
Name<-c("Tom", "Jim", "Sam", "Smith", "Bill", "John", "Kim", "Jill", "Rob", "Son", "Moon", "Star")
ave1<-c(1,2,3,4,5,6,7,8,9,10,11,12)
ave2<-c(12,11,10,9,8,7,6,5,4,3,2,1)
table1<-data.frame(School, Name, ave1, ave2)
@

<<graphs, fig.width=3, fig.height=3, out.width='.49\\linewidth', echo=FALSE, fig.show='hold'>>=
ggplot(table1, aes(x=School, y=ave1, fill=Name))+
  geom_bar(position="dodge", stat="identity")+
  theme_bw()+
  scale_fill_grey()+
  ylab("Average 1 Scores")+
  xlab("a vs. b Schools")+
  ggtitle("Means for a and b Schools on average 1")

ggplot(table1, aes(x=School, y=ave2, fill=Name))+
  geom_bar(position="dodge", stat="identity")+
  theme_bw()+
  scale_fill_grey()+
  ylab("Average 2 Scores")+
  xlab("a vs. b Schools")+
  ggtitle("Means for a and b Schools on average 2")
@



\end{document}

感谢您的帮助。

0 个答案:

没有答案