Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R中带有Plotly的子地块_R_R Markdown_Plotly - Fatal编程技术网

R中带有Plotly的子地块

R中带有Plotly的子地块,r,r-markdown,plotly,R,R Markdown,Plotly,我无法使用R中带有R标记的plotly库获得piechart的并排子图。相反,看起来子地块将一个饼覆盖在另一个饼上: --- title: "Test Plotly Pie" author: "" date: "" output: html_document: self_contained: no --- ```{r plotpie1, results='asis', tidy=FALSE, message=FALSE, fig.retina=NULL, echo=FALSE

我无法使用R中带有R标记的plotly库获得piechart的并排子图。相反,看起来子地块将一个饼覆盖在另一个饼上:

---
title: "Test Plotly Pie"
author: ""
date: ""
output:
   html_document:
      self_contained: no
---

```{r plotpie1, results='asis', tidy=FALSE, message=FALSE, fig.retina=NULL, echo=FALSE, out.width = "99%", out.height="750p[![enter image description here][1]][1]x"}

require(plotly)
require(dplyr)

p1 <- plot_ly(type="pie",values=c(5,954), height = 7,
        labels=c("Change","No Change"),textinfo="label", hoverinfo="all",
        textposition="outside",showlegend=F,marker=list(colors=c(
          "lightskyblue",
           "deepblue"
        ))) %>%
  layout(autosize = T)

p2 <- plot_ly(type="pie",values=c(15,1325), height = 7,
        labels=c("Change","No Change"),textinfo="label", hoverinfo="all",
        textposition="outside",showlegend=F,marker=list(colors=c(
          "lightskyblue",
           "deepblue"
        ))) %>%
  layout(autosize = T)

p4 <- suppressWarnings(subplot(
   p1,
   p2,
   margin=0.05))

p4

```
---
标题:“有计划地测试饼图”
作者:“
日期:“”
输出:
html_文件:
自给自足:没有
---
```{r plotpie1,results='asis',tidy=FALSE,message=FALSE,fig.retina=NULL,echo=FALSE,out.width=“99%”,out.height=“750p[![在此处输入图像描述][1][1]x”}
要求(详细地)
需要(dplyr)
p1%
布局(自动调整大小=T)
p2%
布局(自动调整大小=T)

p4正如MLavoie所建议的那样,我将添加一个答案,以防有人发现它有用

```{r message=FALSE, warning=FALSE}
library(plotly)
p <- plot_ly(x = rnorm(1000), y = rnorm(1000), mode = "markers")
```

<div>
 <div style = "float:left">
 ```{r echo = F, fig.width = 4, fig.height = 4}
 p
 ```
 </div>

 <div style = "float:right">
 ```{r, echo = F, fig.width = 4, fig.height = 4}
 p
 ```
 </div>
</div>
`{r message=FALSE,warning=FALSE}
图书馆(绘本)

p问题在于馅饼和子块,而不是我所怀疑的Rmarkdown。。。子批是否不支持饼图类型?或者在子图中有一种不同的方式来调用饼图?“子图不支持饼图类型吗”看起来是这样的..也许其他人会想出一个解决方案,直线图和点图可以很好地工作。饼图实际上没有x轴和y轴…@MLavoie:所以我用你的答案[这里]()来修改我的边距,然后我将out.width和height改为较小的百分比,然后在样式标记中添加了一个“float:left;position:relative”,这是迄今为止我得到的最好答案。。。当我这么做的时候,效果很好。谢谢你的帮助!我很高兴我是有用的:-)你应该张贴你的答案给未来的读者!人们并不总是看评论,我也有同样的问题。不过,来自MLovie或@royr2的解决方案都不起作用。那是r的代码吗?我不懂密码