title: circular bubble chart with R
body: <p>I would like to reproduce the following plot in R:</p>
  
  <p><a href="https://i.stack.imgur.com/f852r.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/f852r.jpg" alt="bubble chart"></a></p>
  
  <p>I am now using the package <em>packcircles</em> and I am able to create the plot in the figure: </p>
  
  <p><a href="https://i.stack.imgur.com/hTySk.png" rel="nofollow noreferrer">packcircles plot</a></p>
  
  <p>using the following code:</p>
  
  <pre><code>require(packcircles)
  res &lt;- circleLayout(xyr, limits, limits, maxiter = 1000)
  dat &lt;- circlePlotData(res$layout)
  
  doPlot &lt;- function(dat, title)
  ggplot(dat) + 
  geom_polygon(aes(x, y, group=id), colour="tomato", fill="tomato", alpha=0.3) +
  coord_equal(xlim=limits, ylim=limits) +
  theme_bw() +
  theme(axis.text=element_blank(),
      axis.ticks=element_blank(),
      axis.title=element_blank()) +
  labs(title=title)
  
  doPlot(dat, "")
  </code></pre>
  
  <p>where <em>xyr</em> is a dataframe of the form:</p>
  
  <pre><code>          x           y    r
  1  2.897344 -10.4161236 0.57
  2  1.932411  13.0631120 0.52
  3  6.839500 -11.0507209 0.52
  4 11.117047 -17.6440597 0.77
  5 22.395529  -0.6191146 0.45
  6 20.313309 -13.3292887 0.69
  </code></pre>
  
  <p>and the output <em>dat</em> of the form:</p>
  
  <pre><code>         x         y id
  1 10.72973 -14.18673  1
  2 10.71182 -14.04498  1
  3 10.65923 -13.91213  1
  4 10.57524 -13.79654  1
  5 10.46515 -13.70546  1
  6 10.33587 -13.64463  1
  </code></pre>
  
  <p>It's a good start, but I need to label and color the circles according to a certain variable. Apparently, the rows in <em>dat</em> are not in the same order as in the input dataframe. Therefore, I'm note able to add any other information to <em>dat</em> (e.g., a new variable) to be used to group circles by color in <em>ggplot2</em>, because I lost any references to the original data.</p>
  
  <p>Following the suggestion of @rawr, I used <em>bubbles</em> package to reproduce the plot with the following code:</p>
  
  <pre><code>require(bubbles)
  text = as.character(seq(from = 1, to = 476))
  bubbles(value = count,
          color = rainbow(length(count), alpha=NULL)[sample(length(count))],
          label = text,
          width=1600, height=1600)
  </code></pre>
  
  <p>where <em>count</em> is a numeric vector in [0,1]. The output is the following:</p>
  
  <p><a href="https://i.stack.imgur.com/PHPi5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PHPi5.png" alt="bubbles plot"></a></p>
  
  <p>The library allows to provide a different color for each circle, but it's not possible to color circles by group. Also, it allows for setting labels in a very straightforward way, differently from <em>packcircles</em>. Anyway, I couldn't export the plot directly from R, but I had to output it as a part of an R Markdown document.  </p>