在使用knitr生成pdf时,如何在RMarkdown中将R代码和图形保持在同一页面上

时间:2015-10-25 10:58:37

标签: r knitr r-markdown

在RMarkdown中是否有办法强制使用R代码并将其生成的数字显示在同一页面上?我正在使用Knit pdf。例如,

CREATE TABLE `Posts`(
    `Id` int NOT NULL, 
    `CreationDate` datetime NOT NULL, 
    `Content` longtext NOT NULL, 
    `ThreadId` int NOT NULL
)
ALTER TABLE `Posts` ADD PRIMARY KEY (Id)
ALTER TABLE `Posts` ADD CONSTRAINT Thread_Post
ALTER TABLE `Posts` ADD KEY (`ThreadId`)
ALTER TABLE `Posts` ADD CONSTRAINT Thread_Replys
ALTER TABLE `Posts` ADD CONSTRAINT Thread_Post
    FOREIGN KEY (Id)
    REFERENCES `Threads` (Id)
ALTER TABLE `Posts` ADD CONSTRAINT Thread_Replys
    FOREIGN KEY (ThreadId)
    REFERENCES `Threads` (Id)
ALTER TABLE `Posts` ADD CONSTRAINT Thread_Replys
    FOREIGN KEY (ThreadId)
    REFERENCES `Threads` (Id)
    ON DELETE NO ACTION ON UPDATE NO ACTION

CREATE TABLE `Threads`(
    `Id` int NOT NULL AUTO_INCREMENT UNIQUE, 
    `Title` longtext NOT NULL, 
    `PostId` int NOT NULL, 
    `ViewsCount` int NOT NULL, 
    `IsClosed` bool NOT NULL, 
    `IsVisible` bool NOT NULL, 
    `ReplysCount` int NOT NULL
)
ALTER TABLE `Threads` ADD PRIMARY KEY (Id)

(不可再现)在一页上生成代码,在下一页生成一个图。我已尝试全局设置图形宽度和高度,例如

```{r}
ggplot(df, aes(x = x, y = y, col = sex_f)) + geom_point() +
  ggtitle("Data from Children") +
  labs(x = "Age (months)", y = "Height (cms)", col = "Child Gender") +
  geom_smooth(method = "lm", se = FALSE) + 
  facet_grid(sex_f ~ town_f)
```

值非常小,但这并不能阻止所有错误的分页符。谢谢。

0 个答案:

没有答案