小编Jul*_*der的帖子

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

在RMarkdown中有没有办法强制R代码和它产生的数字出现在同一页面上吗?我正在使用Knit pdf.例如,

```{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)
```
Run Code Online (Sandbox Code Playgroud)

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

```{r global_options, include=FALSE}
knitr::opts_chunk$set(fig.width = 4, fig.height = 3, 
                       fig.path = 'Intro_Figs/',
                       fig.show = 'asis',
                       fig.align = 'center',
                       warning = FALSE, message = FALSE)
```
Run Code Online (Sandbox Code Playgroud)

具有非常小的值,但这不会阻止所有错误的分页符.谢谢.

r knitr r-markdown

6
推荐指数
0
解决办法
1101
查看次数

在ggplot2中的图例键中更改符号

此R代码产生一个ggplot2图,其中图例键包含以红色,蓝色和绿色重复的字母“ a”。

x <- rnorm(9); y <- rnorm(9); s <- rep(c("F","G","K"), each = 3)
df <- data.frame(x, y, s)

require(ggplot2)
ggplot(df, aes(x = x, y = y, col = s, label = s)) + 
geom_text() +
scale_colour_discrete(name = "My name", breaks = c("F","K","G"), labels = c("Fbig","Kbig","Gbig")) 
Run Code Online (Sandbox Code Playgroud)

我想将图例键中重复的“ a”替换为“ F”,“ K”和“ G”。

请问这可能吗?谢谢。

r ggplot2

5
推荐指数
1
解决办法
3300
查看次数

标签 统计

r ×2

ggplot2 ×1

knitr ×1

r-markdown ×1