【问题标题】:Adjust the size of plotly charts in slidify在 slidify 中调整绘图图表的大小
【发布时间】:2016-04-23 22:44:24
【问题描述】:

我在 R 中创建了一个 plotly 图表,然后通过 htmlwidget 保存该图,以便可以在 slidify 中调用该图。我在layoutindex.Rmd 中都使用了widthheight,以使绘图适合滑动幻灯片,但当一些文本添加在一起时,最终结果总是会切掉图表的底部。

如何在 slidify 中真正调整 plotly 图表的大小?

R 脚本中的代码

## first slide
date <- seq(from = as.POSIXct("2015/4/1"),
            to = as.POSIXct("2015/10/1"),
            by = "month")

as.Date(date, "%Y/%m/%d")

set.seed(2016)
tot.prem <- runif(n = 7, min = 0, max = 1200)
pol.frce <- runif(n = 7, min = 0, max = 6000)
tot.data <- cbind(date, tot.prem, pol.frce)
tot.data <- data.frame(Date = as.POSIXct(date, format = "%Y/%m/%d"), 
                  WP = tot.prem, 
                  PIF = pol.frce)

m = list(
  l = 50,
  r = 50,
  b = 100,
  t = 100,
  pad = 4
)

p1 <- tot.data %>% 
  subplot(plot_ly(x = date, y = tot.prem, type = "bar"),
          plot_ly(x = date, y = pol.frce, type = "bar"), margin = 0.05) %>% 
  layout(showlegend = FALSE, 
         title = "Written Premium and PIF", 
         yaxis = list(title = "WP (in Millions)", showgrid = FALSE),
         xaxis = list(title = "Date"),
         yaxis2 = list(title = "Policy in Force", showgrid = FALSE),
         xaxis2 = list(title = "Date"),
         autosize = F, width = 600, height = 400, margin = m
         )
p1
# saveWidget(dplot, 'plotlyex1.html')
htmlwidgets::saveWidget(as.widget(p1), "wp.html")

index.Rmd 的摘录

## Program Summary

- Point 1: blah blah blah
- Point 2: blah blah blah
- Point 3: blah blah blah

```{r wp, echo=FALSE, warning=FALSE, cache=FALSE, results='asis'}
cat('<iframe src="./assets/widgets/wp.html" width=100% height=10% allowtransparency="true"> </iframe>')
```

---

幻灯片

【问题讨论】:

    标签: r r-markdown plotly slidify


    【解决方案1】:

    我找到了文本问题的解决方案,但没有找到您的尺寸查询。如果您在图表下方放置一些文本,则 x 轴文本将正确显示。如果您不想要文本,也可以使用空白字符,如下所示:

    ```{r wp, echo=FALSE, warning=FALSE, cache=FALSE, results='asis'}
    cat('<iframe src="./assets/widgets/wp.html" width=100% height=10% allowtransparency="true"> </iframe>')
    ```
    &#032;
    

    你的代码帮助我在 Slidify 中获得了我的第一个 Plotly 显示,所以谢谢你。

    【讨论】:

      猜你喜欢
      • 2016-08-09
      • 2012-03-25
      • 2017-08-13
      • 1970-01-01
      • 2012-05-08
      • 2017-11-04
      • 2018-06-27
      • 2016-05-06
      • 2023-03-21
      相关资源
      最近更新 更多