3

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

```

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).

5
  • the problem is with pie and subplots, not with Rmarkdown Commented Feb 5, 2016 at 20:51
  • As I suspected... Is the pie type not supported with subplot? Or is there just a different way that you are supposed to call pie's within the subplot? Commented Feb 7, 2016 at 20:51
  • "Is the pie type not supported with subplot" it looks like it..maybe somebody else will come up with a solution, line and point graphs work fine. Pie chart don't really have x and y axis.... Commented Feb 7, 2016 at 21:06
  • @MLavoie : So I took your answer [here] (stackoverflow.com/questions/35002772/pie-chart-labels-cut-off) to modify my margins, and then I changed the out.width and height to smaller percentages, then threw a "float: left; position: relative" into the style tag, and that is the best answer I have thus far... Works great though when I do that. Thanks for the help! Commented Feb 8, 2016 at 14:39
  • I am happy I was useful :-) You should post your answer for future readers! People don't always look into the comments. Commented Feb 8, 2016 at 14:44

1 Answer 1

2

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>
Sign up to request clarification or add additional context in comments.

1 Comment

I have the same problem. Neither the solution from MLovie or @royr2 works, though. Is that code for r? I don't understand the code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.