2

我试图在 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}

谢谢您的帮助。

4

0 回答 0