【问题标题】:Not able to plot side by side plotly bar plots in R Shiny flexdashboard无法在 R Shiny flexdashboard 中并排绘制条形图
【发布时间】:2018-02-19 10:49:03
【问题描述】:

我必须设计一个闪亮的 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,即垂直并排)。

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

我哪里错了??

【问题讨论】:

  • 我不知道如何解决您的问题,但是当我注释掉 ggplotly(p1) 并用 pairs(iris) 替换它时,我在同一个选项卡上根据需要有两个图。这表明这是 ggplotly 的问题

标签: r shiny flexdashboard


【解决方案1】:

我们可以使用subplot

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

-完整代码


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}
```

-输出

【讨论】:

    猜你喜欢
    • 2019-06-15
    • 1970-01-01
    • 2020-11-08
    • 1970-01-01
    • 1970-01-01
    • 2015-10-09
    • 2017-06-30
    • 2019-04-29
    • 1970-01-01
    相关资源
    最近更新 更多