无法在R Shiny flexdashboard中并排绘制情节条形图

时间:2017-09-11 08:46:32

标签: r shiny flexdashboard

我必须设计一个Shiny flexdashboard,我想在两个条形图中绘制一个“单一”标签。

我正在尝试的是以下内容:

---
title: "My Dashboard"
output: 
  flexdashboard::flex_dashboard:
    orientation: column
    vertical_layout: fill        
---

```{r setup, include=FALSE}
library(flexdashboard)
library(ggplot2)
library(plotly)
library(plyr)
```


My Page
===================================== 

Column {data-width=260 .tabset}
-----------------------------------------------------------------------

### Tab 1

```{r}

```

### Tab 2

```{r}

```

### Tab 3

```{r}

```

Column {.tabset}
-----------------------------------------------------------------------

### REGION 1

```{r}

# Make some noisily increasing data
set.seed(955)
dat <- data.frame(cond = rep(c("A", "B"), each=10),
                  xvar = 1:20 + rnorm(20,sd=3),
                  yvar = 1:20 + rnorm(20,sd=3))


p1 <- ggplot(dat, aes(x=xvar, y=yvar)) +
            geom_point(shape=1)      # Use hollow circles
ggplotly(p1)


p2 <- ggplot(dat, aes(x=xvar, y=yvar)) +
            geom_point(shape=1) +    # Use hollow circles
            geom_smooth(method=lm)   # Add linear regression line
ggplotly(p2)

```

### REGION 2

```{r}
```

我没有并排拍摄地块(1 x 2,即垂直并排)。

使用上面的代码,我应该可以在单个选项卡中获得两个图,但实际上我得到一个。此外,我希望两个地块彼此相邻。但看起来我在这里遇到了一些可怕的错误。

我错在哪里?

1 个答案:

答案 0 :(得分:3)

我们可以使用subplot

subplot(ggplotly(p1), ggplotly(p2))

-full code

title: "My Dashboard"
output: 
  flexdashboard::flex_dashboard:
  orientation: column
vertical_layout: fill        
---

```{r setup, include=FALSE}
library(flexdashboard)
library(ggplot2)
library(plotly)
library(plyr)   
```


My Page
===================================== 

  Column {data-width=260 .tabset}
-----------------------------------------------------------------------

### Tab 1

```{r}

```

### Tab 2

```{r}

```

### Tab 3

```{r}

```

Column {.tabset}
-----------------------------------------------------------------------

### REGION 1

```{r}

# Make some noisily increasing data
set.seed(955)
dat <- data.frame(cond = rep(c("A", "B"), each=10),
                  xvar = 1:20 + rnorm(20,sd=3),
                  yvar = 1:20 + rnorm(20,sd=3))


p1 <- ggplot(dat, aes(x=xvar, y=yvar)) +
  geom_point(shape=1)      # Use hollow circles


p2 <- ggplot(dat, aes(x=xvar, y=yvar)) +
  geom_point(shape=1) +    # Use hollow circles
  geom_smooth(method=lm)   # Add linear regression line

subplot(ggplotly(p1), ggplotly(p2))


```

### REGION 2

```{r}
```

-output

enter image description here