如何调整 div containing plotly 以绘制尺寸,使其不与文档重叠
How to adjust div containing plotly to plot dimensions so it does not overlap document
我正在使用 plotly 在 RMarkdown 中生成绘图。
但是,由于它嵌入在 div 中,因此它与以下文本重叠。
我认为这是因为 plotly 大小和 div.
之间的冲突
---
title: "TITLE"
author: "AUTHOR"
date: "1/1/2000"
output:
html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(
warning = FALSE,
message = FALSE,
echo = FALSE # show R code
)
```
## scatter 1
```{r, echo=FALSE, eval=TRUE,out.width="100%",out.height="100%",fig.align='center'}
library(plotly)
library(htmltools)
mtcars$am[which(mtcars$am == 0)] <- 'Automatic'
mtcars$am[which(mtcars$am == 1)] <- 'Manual'
mtcars$am <- as.factor(mtcars$am)
fig <- plot_ly(mtcars, x = ~wt, y = ~hp, z = ~qsec, color = ~am, colors = c('#BF382A', '#0C4B8E'))
fig <- fig %>% add_markers()
fig <- fig %>% layout(scene = list(xaxis = list(title = 'Weight'),
yaxis = list(title = 'Gross horsepower'),
zaxis = list(title = '1/4 mile time')))
fig %>% layout(autosize = F, width = 1000, height = 800,paper_bgcolor = 'rgb(243, 243, 243)', margin = list(r = 10,t = 25,b = 40,l = 110)) -> p
div(p,align='center')
```
# HEADING
asdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasda
如您所见,文本已隐藏。如何调整 div 属性使其可见?
从块选项中删除 out.height="100%"
。
此外,在 plotly
函数中设置宽度和高度,而不是在 layout
中设置。
---
title: "TITLE"
author: "AUTHOR"
date: "1/1/2000"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(
warning = FALSE,
message = FALSE,
echo = FALSE # show R code
)
```
## scatter 1
```{r, echo=FALSE, eval=TRUE, out.width="100%", fig.align='center'}
library(plotly)
library(htmltools)
mtcars$am[which(mtcars$am == 0)] <- 'Automatic'
mtcars$am[which(mtcars$am == 1)] <- 'Manual'
mtcars$am <- as.factor(mtcars$am)
fig <- plot_ly(
mtcars,
x = ~ wt,
y = ~ hp,
z = ~ qsec,
color = ~ am,
colors = c('#BF382A', '#0C4B8E'),
width = 1000,
height = 800
)
fig <- fig %>% add_markers()
fig <- fig %>% layout(scene = list(xaxis = list(title = 'Weight'),
yaxis = list(title = 'Gross horsepower'),
zaxis = list(title = '1/4 mile time')))
fig %>% layout(
autosize = F,
paper_bgcolor = 'rgb(243, 243, 243)',
margin = list(
r = 10,
t = 25,
b = 40,
l = 110
)
) -> p
div(p, align='center')
```
# HEADING
asdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasda
我正在使用 plotly 在 RMarkdown 中生成绘图。 但是,由于它嵌入在 div 中,因此它与以下文本重叠。 我认为这是因为 plotly 大小和 div.
之间的冲突 ---
title: "TITLE"
author: "AUTHOR"
date: "1/1/2000"
output:
html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(
warning = FALSE,
message = FALSE,
echo = FALSE # show R code
)
```
## scatter 1
```{r, echo=FALSE, eval=TRUE,out.width="100%",out.height="100%",fig.align='center'}
library(plotly)
library(htmltools)
mtcars$am[which(mtcars$am == 0)] <- 'Automatic'
mtcars$am[which(mtcars$am == 1)] <- 'Manual'
mtcars$am <- as.factor(mtcars$am)
fig <- plot_ly(mtcars, x = ~wt, y = ~hp, z = ~qsec, color = ~am, colors = c('#BF382A', '#0C4B8E'))
fig <- fig %>% add_markers()
fig <- fig %>% layout(scene = list(xaxis = list(title = 'Weight'),
yaxis = list(title = 'Gross horsepower'),
zaxis = list(title = '1/4 mile time')))
fig %>% layout(autosize = F, width = 1000, height = 800,paper_bgcolor = 'rgb(243, 243, 243)', margin = list(r = 10,t = 25,b = 40,l = 110)) -> p
div(p,align='center')
```
# HEADING
asdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasda
如您所见,文本已隐藏。如何调整 div 属性使其可见?
从块选项中删除 out.height="100%"
。
此外,在 plotly
函数中设置宽度和高度,而不是在 layout
中设置。
---
title: "TITLE"
author: "AUTHOR"
date: "1/1/2000"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(
warning = FALSE,
message = FALSE,
echo = FALSE # show R code
)
```
## scatter 1
```{r, echo=FALSE, eval=TRUE, out.width="100%", fig.align='center'}
library(plotly)
library(htmltools)
mtcars$am[which(mtcars$am == 0)] <- 'Automatic'
mtcars$am[which(mtcars$am == 1)] <- 'Manual'
mtcars$am <- as.factor(mtcars$am)
fig <- plot_ly(
mtcars,
x = ~ wt,
y = ~ hp,
z = ~ qsec,
color = ~ am,
colors = c('#BF382A', '#0C4B8E'),
width = 1000,
height = 800
)
fig <- fig %>% add_markers()
fig <- fig %>% layout(scene = list(xaxis = list(title = 'Weight'),
yaxis = list(title = 'Gross horsepower'),
zaxis = list(title = '1/4 mile time')))
fig %>% layout(
autosize = F,
paper_bgcolor = 'rgb(243, 243, 243)',
margin = list(
r = 10,
t = 25,
b = 40,
l = 110
)
) -> p
div(p, align='center')
```
# HEADING
asdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasdasdas asdasdasdasda