我希望能够在循环中创建 RMarkdown 块。我尝试通过for循环来完成此操作,但没有取得太大成功。我想这可能可以通过 实现,就像在闪亮的应用程序中lapply进行创建一样。UIs然而,到目前为止我还没有取得任何成功。
代表:
---
title: "Untitled"
output:
html_document:
theme: united
highlight: tango
toc: true
toc_float:
collapsed: false
smooth_scroll: false
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, message = FALSE, warning = FALSE)
```
```{r}
library(dplyr)
library(ggplot2)
df <- datasets::iris %>%
dplyr::as_tibble()
```
## setosa
```{r}
df %>%
dplyr::filter(Species == "setosa") %>%
ggplot2::ggplot(ggplot2::aes(Sepal.Length, Petal.Length)) +
ggplot2::geom_point()
```
## versicolor
```{r}
df %>%
dplyr::filter(Species == "versicolor") %>%
ggplot2::ggplot(ggplot2::aes(Sepal.Length, Petal.Length)) +
ggplot2::geom_point()
```
## virginica …Run Code Online (Sandbox Code Playgroud) I am having issues when knitting my rmarkdown file to PDF with large plots. The plots get cut when producing the PDF file.
The problem is that I can't find a way to automatically adjust the height and width of all the plots. As I am writing a very large report, I have several plots like this, thus adjusting them separately (through fig.width and fig.height) is out of question.
Is there any package/command that I should use in my YAML …
如果我有以下数据:
df <- structure(list(x = c(1.63145539094563, 1.67548187017034, 1.71950834939504,
1.76353482861975, 1.80756130784445, 1.85158778706915, 1.89561426629386,
1.93964074551856, 1.98366722474327, 2.02769370396797, 2.07172018319267,
2.11574666241738, 2.15977314164208, 2.20379962086679, 2.24782610009149,
2.2918525793162, 2.3358790585409, 2.3799055377656, 2.42393201699031,
2.46795849621501, 2.51198497543972, 2.55601145466442, 2.60003793388912,
2.64406441311383, 2.68809089233853, 2.73211737156324, 2.77614385078794,
2.82017033001265, 2.86419680923735, 2.90822328846205, 2.95224976768676,
2.99627624691146, 3.04030272613617, 3.08432920536087, 3.12835568458557,
3.17238216381028, 3.21640864303498, 3.26043512225969, 3.30446160148439,
3.3484880807091, 3.3925145599338, 3.4365410391585, 3.48056751838321,
3.52459399760791, 3.56862047683262, 3.61264695605732, 3.65667343528202,
3.70069991450673, 3.74472639373143, 3.78875287295614), y = c(24.144973858154,
18.6408277478876, 21.9174270206615, 22.8017876727379, 20.9766270378248,
18.604384256745, 18.4805250429826, 15.8436744335752, 13.6357170277296,
11.6228806771368, 9.4065868126964, 6.81644596802601, 4.41187500831424,
4.31911614349431, 0.678259284890563, -1.18632719250877, -2.32986407762089,
-3.84480566043122, -5.24738510499144, -5.20160089844013, -5.42094587600499, …Run Code Online (Sandbox Code Playgroud) 借用这个问题的示例数据,如果我有以下数据并且我将以下非线性模型拟合到它,我如何计算我的曲线的95%预测 区间?
library(broom)
library(tidyverse)
x <- seq(0, 4, 0.1)
y1 <- (x * 2 / (0.2 + x))
y <- y1 + rnorm(length(y1), 0, 0.2)
d <- data.frame(x, y)
mymodel <- nls(y ~ v * x / (k + x),
start = list(v = 1.9, k = 0.19),
data = d)
mymodel_aug <- augment(mymodel)
ggplot(mymodel_aug, aes(x, y)) +
geom_point() +
geom_line(aes(y = .fitted), color = "red") +
theme_minimal()
Run Code Online (Sandbox Code Playgroud)
举个例子,我可以轻松地从线性模型计算预测区间,如下所示:
## linear example
d2 <- d %>%
filter(x > …Run Code Online (Sandbox Code Playgroud) 我有新的Ubuntu迪斯科19.04,并且按照这里的说明安装新的R 3.6。
但是,在安装密钥并通过以下方式添加存储库之后:
sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu disco-cran35/'
Run Code Online (Sandbox Code Playgroud)
并运行:
sudo apt update
sudo apt install r-base
Run Code Online (Sandbox Code Playgroud)
我得到:
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following …Run Code Online (Sandbox Code Playgroud) 当ggplot2使用拼凑组合对象时,我希望能够有一个选项,我可以轻松地为所有图设置一个选项,使其具有相同的 x 轴和/或 y 轴范围。
代表:
library(patchwork)
library(ggplot2)
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
p1 <- mtcars %>%
ggplot() +
geom_point(aes(mpg, disp)) +
ggtitle('Plot 1')
p2 <- mtcars %>%
filter(disp < 300) %>%
ggplot() +
geom_point(aes(mpg, disp)) +
ggtitle('Plot 2')
p1 + p2
Run Code Online (Sandbox Code Playgroud)

由reprex 包(v0.3.0)于 2020 年 2 …
我有以下数据框:
df <- data.frame(
x = rep(letters[1:3], 2)
)
Run Code Online (Sandbox Code Playgroud)
以下向量:
vec <- c(1.5, 3.2)
Run Code Online (Sandbox Code Playgroud)
该载体属于每个b在df.vec如果匹配则如何变异b并返回NA值?
预期结果:
1 a NA
2 b 1.5
3 c NA
4 a NA
5 b 3.2
6 c NA
Run Code Online (Sandbox Code Playgroud) 如果我有以下数据:
structure(list(x = c(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28,
29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 40, 41, 42, 43, 44, 45,
46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61,
62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, …Run Code Online (Sandbox Code Playgroud)