我正在尝试从data.frames列表中绘制多个图。我正在使用Markdown来呈现数据。在R-Studio中,当我点击">"按下按钮,我得到了所有的情节。
我尝试使用的代码是:
print(summary(seriesFigureSaleDataBS6I_PhaseWave))
Length Class Mode
40th.1 35 data.frame list
40th.2 35 data.frame list
40th.Legacy 35 data.frame list
Blue.5 35 data.frame list
Blue.6 35 data.frame list
Blue.7 35 data.frame list
Blue.8 35 data.frame list
...
列表如下:
## [[1]]
##
## [[2]]
##
## [[3]]
##
## [[4]]
##
## [[5]]
运行模式下的输出如下所示:
编织输出只给我R控制台输出:
for(i in 1:length(seriesFigureSaleDataBS6I_PhaseWave)) {
print(plot_ly(data = seriesFigureSaleDataBS6I_PhaseWave[[i]],
x = ~priceDate,
y = ~amount,
color = ~actionFigurePackageName,
colors = "Pastel2",
type = "scatter",
mode = "markers") %>%
layout(title = paste("Phase", seriesFigureSaleDataBS6I_PhaseWave[[i]]$Phase, "& Wave", seriesFigureSaleDataBS6I_PhaseWave[[i]]$Wave)))
}
如果我尝试以下代码,我将丢失R控制台输出(这很好),并在R-Studio"运行"模式,但在编织模式下没有绘图输出:
Validator::extend('numericarray', function($attribute, $value, $parameters)
{
foreach($value as $v) {
if(!is_int($v)) return false;
}
return true;
});
答案 0 :(得分:3)
使用htmltools::tagList
功能:
---
title: "Knit a List of Plotly Graphs"
output: html_document
---
```{r, include = F}
library(dplyr)
library(plotly)
library(htmltools)
```
```{r, echo=TRUE, eval=TRUE}
dat <- list(mtcars, mtcars)
plots <- lapply(dat, function(x) {
plot_ly(data = x, x = ~hp, y = ~mpg) %>%
add_trace(type = "scatter", mode = "markers")
})
tagList(plots)
```