R中具有Plotly的子图 [英] Subplot with Plotly in R
本文介绍了R中具有Plotly的子图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法使用带有R Markdown的R中的绘图库来获得饼图的并排子图.相反,子图看起来像是将一个饼图叠加在另一个饼图上
I cannot get a side by side subplot of a piechart using the plotly library in R with R Markdown. Instead, it looks like the subplot is overlaying one pie on top of the other:
---
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
```
我在Windows 7 64位操作系统上使用R 3.1.3 64位.我使用的是程序包版本2.0.16(2015年12月中旬从Github下载).
I am using R 3.1.3 64-bit on a Windows 7 64-bit operating system. I am using the plotly package version: 2.0.16 (downloaded from Github in mid December of 2015).
推荐答案
如 MLavoie 所建议,我只是添加一个答案,以防有人觉得有用...
As suggested by MLavoie, I'll just add an answer in case someone finds it useful...
```{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中具有Plotly的子图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文