r - Create bubble chart with biggest bubble at the center -


i'm trying create bubble chart using set of data follows:

x --> 10 y --> 20 z --> 5 q --> 10 

i need have biggest bubble (based on number) @ centre (give or take) , rest of bubbles around without overlapping.

all of r examples have seen require 2 dimensional dataset, , since data have 1 dimensional, know if it's @ possible create such graphs in r.

it great if suggest me useful hints or so. way task need use sa tools d3js out of options. however, open using tool other r.

i wasn't quite sure if question should asked in on stack overflow or cross validated, if moderators believe doesn't belong here, i'll remove it.

this should do, main idea being sort value of radius, first biggest, shift values around (odd on 1 side, on other) values decreasing both ways.

further explanations in code.

library(plotrix) library(rcolorbrewer)  # set random seed, reproducible results set.seed(54321)  # generate random values radius num.circles <- 11 rd <- runif(num.circles, 1, 20)  df <- data.frame(labels=paste("lbl", 1:num.circles), radius=rd)  # sort descending radius. biggest circle row 1 df <- df[rev(order(df$radius)),]  # want put biggest circle in middle , others on either side # reorder data frame taking values first reversed, odd values. # ensure biggest circle in middle  df <- df[c(rev(seq(2, num.circles, 2)), seq(1, num.circles, 2)),]  # space between circles. 0.2 * average radius seems ok space.between <- 0.2 * mean(df$radius)  # creat empty plot plot(0, 0, "n", axes=false, bty="n", xlab="", ylab="",       xlim=c(0, sum(df$radius)*2+space.between*num.circles),      ylim=c(0, 2.5 * max(df$radius)))  # draw circle @ half height of biggest circle (plus padding) xx <- 0 mid.y <- max(df$radius) * 1.25  # nice degrading tones of blue colors <- colorramppalette(brewer.pal(8,"blues"))(num.circles/2)  (i in 1:nrow(df))   {   row <- df[i,]   x <- xx + row$radius + i*space.between   y <- mid.y    # draw circle   draw.circle(x, y, row$radius,                col=colors[abs(num.circles/2-i)])   # add label   text(x, y, row$labels, cex=0.6)    # update current x position   xx <- xx + row$radius * 2   } 

the result: circles

live version on rfiddle.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -