2 基于一个闪亮的小部件在 Rmarkdown 中并排绘制
2 Plots side by side in Rmarkdown based on one shiny widget
我有问题。我想在 Rmarkdown 文档中并排放置两个图:
```{r, echo = FALSE}
library(ggplot2)
library(shiny)
```
```{r, echo = FALSE,fig.show='hold', out.width='50%'}
ggplot(mtcars,aes(qsec, mpg)) +
geom_point()
ggplot(mtcars,aes(disp, mpg)) +
geom_point()
```
而且效果很好。但另外我想添加与这两个图相关的闪亮小部件。这样,图就不会并排显示了。
```{r, echo = FALSE, fig.show='hold', out.width='50%'}
iteration <- sort(unique(mtcars$cyl))
selectInput('cyl', 'Choose number of cylinder:',
choices = iteration,
selected = iteration[1])
data <- reactive(subset(mtcars,cyl == input$cyl))
renderPlot(ggplot(data(),aes(qsec, mpg)) +
geom_point())
renderPlot(ggplot(data(),aes(disp, mpg)) +
geom_point())
```
我应该更改什么以获得预期的效果?
谢谢。
在这种情况下,您应该个性化您的布局,如 shiny tutorial 中所示,例如分为 2 列:
```{r, echo = FALSE, fig.show='hold', out.width='50%'}
iteration <- sort(unique(mtcars$cyl))
selectInput('cyl', 'Choose number of cylinder:',
choices = iteration,
selected = iteration[1])
data <- reactive(subset(mtcars,cyl == input$cyl))
fluidRow(
column(6,
renderPlot(ggplot(data(),aes(qsec, mpg)) +
geom_point())
),
column(6,
renderPlot(ggplot(data(),aes(disp, mpg)) +
geom_point())
)
)
```
在这种情况下,我使用了流体等级系统,您可以将其更改为固定 (fixedRow
)
我有问题。我想在 Rmarkdown 文档中并排放置两个图:
```{r, echo = FALSE}
library(ggplot2)
library(shiny)
```
```{r, echo = FALSE,fig.show='hold', out.width='50%'}
ggplot(mtcars,aes(qsec, mpg)) +
geom_point()
ggplot(mtcars,aes(disp, mpg)) +
geom_point()
```
而且效果很好。但另外我想添加与这两个图相关的闪亮小部件。这样,图就不会并排显示了。
```{r, echo = FALSE, fig.show='hold', out.width='50%'}
iteration <- sort(unique(mtcars$cyl))
selectInput('cyl', 'Choose number of cylinder:',
choices = iteration,
selected = iteration[1])
data <- reactive(subset(mtcars,cyl == input$cyl))
renderPlot(ggplot(data(),aes(qsec, mpg)) +
geom_point())
renderPlot(ggplot(data(),aes(disp, mpg)) +
geom_point())
```
我应该更改什么以获得预期的效果?
谢谢。
在这种情况下,您应该个性化您的布局,如 shiny tutorial 中所示,例如分为 2 列:
```{r, echo = FALSE, fig.show='hold', out.width='50%'}
iteration <- sort(unique(mtcars$cyl))
selectInput('cyl', 'Choose number of cylinder:',
choices = iteration,
selected = iteration[1])
data <- reactive(subset(mtcars,cyl == input$cyl))
fluidRow(
column(6,
renderPlot(ggplot(data(),aes(qsec, mpg)) +
geom_point())
),
column(6,
renderPlot(ggplot(data(),aes(disp, mpg)) +
geom_point())
)
)
```
在这种情况下,我使用了流体等级系统,您可以将其更改为固定 (fixedRow
)