Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmarindiaz committed Mar 10, 2015
0 parents commit d477885
Show file tree
Hide file tree
Showing 18 changed files with 2,323 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .Rbuildignore
@@ -0,0 +1,2 @@
^.*\.Rproj$
^\.Rproj\.user$
21 changes: 21 additions & 0 deletions .gitignore
@@ -0,0 +1,21 @@
# History files
.Rhistory
.Rapp.history

# Example code in package build process
*-Ex.R

# RStudio files
.Rproj.user/
.Rproj.user/*

# RData
.RData

# produced vignettes
vignettes/*.html
vignettes/*.pdf

*.Rproj

.Rproj.user
11 changes: 11 additions & 0 deletions DESCRIPTION
@@ -0,0 +1,11 @@
Package: bubbleCloud
Type: Package
Title: d3 bubble plots
Version: 1.0
Date: 2015-03-05
Author: Juan Pablo Marín Díaz
Maintainer: Juan Pablo Marín Díaz <jpmarindiaz@gmail.com>
Description: d3 bubble plots
License: MIT + file LICENSE
Imports:
htmlwidgets (>= 0.3)
21 changes: 21 additions & 0 deletions LICENSE
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (C) 2015, Jp Marín Díaz, http://github.com/jpmarindiaz/bubbleCloud

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
1 change: 1 addition & 0 deletions NAMESPACE
@@ -0,0 +1 @@
exportPattern("^[^\\.]")
87 changes: 87 additions & 0 deletions R/bubbles.R
@@ -0,0 +1,87 @@
#' <Add Title>
#'
#' <Add Description>
#'
#' @import htmlwidgets
#'
#' @export
bubbles <- function(data, name = "bubbleForce", width = NULL, height = NULL) {

# if(is.null(data$id)) data$id <- seq(1:nrow(data))

if(!"data.frame" %in% class(data)) {
stop("data must be a dataframe")
}

if (is.null(data$x)){
message("No node x position provided: using random value")
data$x <- runif(nrow(data),1,10)
}

if (is.null(data$y)){
message("No node y position provided: using random value")
data$y <- runif(nrow(data),1,10)
}

if (is.null(data$radius)){
message("No radius provided: using fixed value = 5")
data$radius <- 5
}

if (is.null(data$cluster)){
data$cluster <- 0
}

clusters <- ddply(data,.(cluster),function(r){
r <- r[with(r,order(radius)),]
head(r,1)
})

n <- nrow(data)
m <- nrow(clusters)

# Convert to array of objects
data <- apply(data, 1,function(r){
as.list(r)
})
names(data) <- NULL

clusters <- apply(clusters, 1,function(r){
as.list(r)
})

x = list(
n = n,
m = m,
data = data,
clusters = clusters
)

# create widget
htmlwidgets::createWidget(
name = name,
x,
width = width,
height = height,
package = 'bubbleCloud',
sizingPolicy = htmlwidgets::sizingPolicy(
viewer.padding = 0,
browser.fill = TRUE
)
)
}

#' Widget output function for use in Shiny
#'
#' @export
bubblesOutput <- function(outputId, width = '100%', height = '400px'){
shinyWidgetOutput(outputId, 'bubble', width, height, package = 'bubbleCloud')
}

#' Widget render function for use in Shiny
#'
#' @export
renderBubbles <- function(expr, env = parent.frame(), quoted = FALSE) {
if (!quoted) { expr <- substitute(expr) } # force quoted
shinyRenderWidget(expr, dimplerOutput, env, quoted = TRUE)
}
25 changes: 25 additions & 0 deletions inst/00.R
@@ -0,0 +1,25 @@

library(devtools)
library(htmlwidgets)


devtools::install()
library(bubbleCloud)


data <- read.csv("inst/data/bubbles.csv")
data2 <- data[1:50,]
#bubbles(data)
bubbles(data2[c("cluster")])

bubbles(data2[,2:4])
bubbles(data2[,2:4])

data3 <- data
data3$cluster <- 0
bubbles(data3)


#data <- data[,1]
#bubbles(data)

201 changes: 201 additions & 0 deletions inst/data/bubbles.csv
@@ -0,0 +1,201 @@
cluster,radius,x,y
3,13.112535167220194,418.4648776786116,441.0390176088724
7,5.109421629313969,418.3839366387755,60.606761826883286
5,6.399684516410465,280.5123371533118,250.4649517014623
1,5.353685417110638,642.5425979722578,368.37664308782115
2,9.667569241896562,542.7656292039256,441.0557837912522
0,3.9384915875176345,680.0402610462625,250.84961532638408
4,1.571984771464654,318.76885394246244,368.4969821473249
0,2.8000264276137066,680.1912934342399,250.0133677246049
0,3.2017409371021435,680.4692866180558,250.32656607264653
8,19.854971638346925,541.8850022851775,59.846919028536604
5,12.293038053510433,280.20919276657514,250.61264462443071
9,24.228683858463427,642.7223479043978,133.03159999371124
4,7.445551802003653,318.7010635899559,368.01829506444193
3,6.613311649345535,419.09800948325477,440.54067466852143
6,12.752909334239735,318.7326993926607,133.1470062643159
2,3.141408731906364,542.7264889135778,440.570647446689
9,13.755586482500696,642.4098821826565,133.2761081772725
7,4.931984469659047,418.3377779515639,60.38438170587759
0,2.445757389387995,680.970882355934,250.9852028361056
4,10.048264745191311,319.0026540209718,367.62567051138177
4,10.39983124590512,318.52875106089675,368.06755438946567
3,12.684235707876542,419.0639862479356,440.9201516399801
7,16.23363287204945,418.4745992746383,59.879318685020536
7,18.02497885887232,418.7211957502358,60.01691493227261
7,11.285297578542357,418.7766304740861,60.58790621858205
6,14.947016158824683,318.5242359466564,132.48787076946905
7,11.206298258423418,418.48457947379836,59.86971273131783
6,13.511607088221218,318.4231442227673,132.85957208474724
5,4.732379180768487,280.04184341803193,250.58028729190121
3,1.2352164109864177,418.7569385076121,440.28775278899707
4,8.895406976516556,318.76233593893164,367.57319201516367
9,10.006870503999414,642.7070683354332,132.4979870586059
3,4.553119871283067,418.2364502051559,440.73105151813365
0,1.907476471999248,680.2310793839861,250.56989199179225
0,3.0394117753751795,680.3522501494735,250.19694326189347
7,6.016525965060481,418.5518042755492,60.139112553774595
8,2.872381632444971,542.746360588987,60.388233951275424
8,1.5966075120576124,542.7116445900692,60.511025942378865
6,3.840057623413583,318.6269897067167,133.32646446128933
8,8.406972561591243,541.8765936295322,60.40435167609826
1,3.916458268609747,642.6492355816819,367.946825842945
7,16.326819436800665,418.89166257839577,60.62329961683716
9,9.22233727188151,642.1455657018168,132.79580304993866
8,4.949697504719074,542.2601767426177,60.612892232584954
2,8.722515638011284,542.2253147931125,440.21506384389363
7,6.855578650920831,418.24415036856124,60.233010777720466
8,7.073883590865945,542.8000601869362,60.72529056852795
8,16.78960421360285,542.0121300997498,60.13127113178484
4,11.857361454549906,318.3378990970731,368.16993966150477
3,4.265035155032514,418.5338251810235,440.47479003250487
5,4.68332362027954,280.58909451123327,250.34044655528854
2,5.439826759386443,542.6099695937529,440.7048686016526
1,10.597133485971387,641.9161224352948,367.84427416544787
5,7.469391511040165,280.5826266182121,250.89719910267743
4,10.658392721920983,319.08339869959207,368.52847905560776
9,12.285946480007397,642.5794645335345,132.93746665691575
1,2.2303203475883446,642.7450575448394,367.7450547256638
9,2.105537168799785,642.4128716226487,133.3916666604447
5,7.372785450634035,280.7644316069782,250.6312318767887
2,6.278579466306951,541.9869568910736,440.6917293484032
0,5.319544639136849,680.6861454262398,250.17822758085094
5,22.5322144083228,280.49568414967507,250.1429544396233
4,12.184907388725737,318.40450190409945,367.77197859214067
0,3.1249446977364643,680.2004468759988,250.0629779114388
4,12.77251841235893,318.8362684292432,367.72203519159376
7,8.085296821574058,418.60624254827314,60.70792843981761
6,10.1694552815525,319.1242634924773,133.21675748413986
9,13.12463210625571,641.9335938903323,132.8155631764195
0,1.885091814686083,680.0634421242867,250.8720285347663
6,5.686142386574278,318.68157234538273,132.65334495961292
4,4.615095995753941,319.04427285172903,368.2790097879377
0,4.4293445362375765,680.1900794992689,250.19003518205136
3,9.46657293505738,418.59553852218136,440.9011929212313
6,5.3685987700396645,318.5361797030263,133.08037468081898
7,10.096971426572527,418.7500107752338,59.80812552336718
3,12.949026531503833,418.3632814193324,440.3179815944925
3,3.0114373797407747,418.76944563521005,440.57484857483655
7,0.69412867307504,419.0336827804048,60.374365620297596
7,3.1158390825567297,419.1085191965748,59.79709102234918
5,2.2358593335989547,280.3530043878127,250.792430984322
4,5.004830427066488,318.4038349318497,368.1012743128129
3,2.9800150011456537,419.10507499735735,441.0264272673696
6,3.4375550780178195,318.7900983088829,133.3231564696282
2,3.738845125312082,542.3149888521813,440.2233801994182
7,11.613121745020063,419.13702171977536,60.54616854244958
2,5.546515154166772,542.1367443142746,440.52969093832075
3,14.6678189599683,418.5842805710335,440.8141302277975
8,5.228090355570616,542.5387776190701,60.67529113053456
2,1.3219143344102031,541.84999747824,440.40456163396016
3,7.138428399766954,418.8322890448098,440.6560583091516
9,3.9948549533780597,642.3756145659654,132.5379562528207
0,2.1526625591880117,680.841872891644,250.8975260592997
5,6.66585025594825,280.8463532847818,250.74671066273007
3,5.693657978420542,419.08520709427006,440.7463373004168
6,15.143410821161808,318.5526297772948,132.4769746124614
3,3.55219492604743,418.2176144337927,440.26699256759025
9,16.23633442890244,642.1453180156468,133.28564149968875
6,7.645419380883134,318.30563801417054,133.3005900270175
1,5.0268620170938085,642.5933176632326,367.874828768069
5,12.961116934367839,280.90199734293856,250.96951084933247
2,3.269699674882224,542.0173350772176,440.5519587083429
0,3.67178763731245,680.3861581194215,250.46763917966746
5,8.00099794337104,280.508698126534,250.94724159874025
7,7.903800525999963,418.43244722911083,60.141048080037564
7,14.027418013917437,418.6850294825334,60.025532993470534
2,5.037449253921186,542.1347208951421,440.9571848823864
3,6.925224482267483,418.6371262286038,440.9289131683938
5,7.993439517662441,280.32898984709755,250.63156764046292
1,1.0049434924039886,642.3550452142309,367.8151216042359
9,12.133450644981103,642.1886091688002,132.8445125141981
0,3.513040917256838,680.0913931198884,250.78628827654757
7,2.4764444735710454,418.5591194804937,60.254686140437826
8,10.008943781917912,542.1250584001473,60.36028159966804
6,6.834531614868232,318.6839117936969,132.71955188655852
1,5.128820817579176,641.9216315533787,368.26593986979134
0,1.8328280754693473,680.2696877850685,250.61747372196987
9,4.1296811875037225,642.2067787248461,133.37792207033922
5,15.400805974430046,280.1190271526575,250.9222197257914
4,6.417868270679037,318.4958637369044,368.28665516419716
7,6.499783469131401,419.07031617273503,59.844487299426675
0,4.974134694720668,680.2810098940972,250.58500051684678
4,5.9899953590668575,319.06901974959226,368.2044677267448
1,2.998405433832767,642.227755156514,367.7334402332679
1,6.721750376658558,642.1864716419306,368.400696345944
9,15.926296027477653,642.3318895203347,133.13171625126702
6,7.909883548205819,318.6985658289112,132.80568844674713
1,5.645287088085665,642.1702355483368,367.71098316261924
4,7.3689274847716195,318.3260378586773,368.22009822527326
6,10.354942426590842,318.49852484890187,132.9824320195578
8,9.966504477801232,541.8571350236243,60.59986321183965
1,2.62046988828486,641.9155201711047,368.0508165395484
5,5.2739958910663916,280.0478266857099,250.4128274896648
2,3.031299685597263,542.2480338173274,441.03785752343833
8,5.982267497038496,542.3613619999314,59.88787512898557
1,8.491265214509042,642.4613517163608,368.3049150822815
1,1.6674837659838984,642.3492123979896,367.7049765082673
1,1.0743142635810603,642.4139816848848,367.58676867477044
8,10.09042547884902,542.5679314915842,60.324500522325934
6,17.177773955740342,318.47740477236846,133.14169632469861
4,3.9086620868272455,319.12083187705764,368.55366477357603
1,2.117058788348487,642.3822065528303,368.4913641024512
7,7.696708571471292,418.38195434102715,60.78685772696625
7,13.822958649340084,418.3032696366489,59.901702956977516
2,7.15756079485079,542.4223189118139,440.27406475741304
7,17.00217904647819,418.4882934305996,59.92789242996949
6,9.705117250652645,318.6962453013465,132.94823776500857
3,8.006628745975163,418.63395077182844,440.67554298464097
2,6.367070683738252,541.8451588718973,441.03623873905167
3,3.1520318247639,418.7585442295012,441.13853963140286
1,2.592782181161132,642.1559631474603,368.3292999301237
7,4.255359639996461,418.7130867588047,60.1490342654113
0,1.282568983571546,680.5560825616121,250.29659985168837
5,13.953460180679892,280.7833365993574,250.38215713016692
4,2.0870211957780653,318.68650846096614,367.68924036655955
4,10.920731225197319,318.6495300594896,367.8767942337916
9,9.80807701716137,641.9487468415691,133.0635977016165
1,0.7125590644314268,642.5498787857879,367.77557072822384
8,13.085663231563025,542.4443391614413,59.833163203421236
8,8.394375345950987,541.9285884571082,59.99982998797782
5,8.549295737337232,280.50973121635616,250.36692920653152
8,8.263387992693154,542.6506468725211,60.765197830722855
2,6.581562857624652,542.7685732212204,440.2224843397446
6,15.359903692875609,319.0821848533295,133.3747934358064
3,13.568389812372281,418.8652145653677,440.2539875845134
6,1.4321784913691942,318.9563855066143,132.56184636115654
9,0.9471094046368066,642.0822761626268,132.73577473697802
5,3.3717434589552404,280.9397696889937,250.08335696277211
9,10.254592222847506,642.5740811880032,132.8576240431386
7,7.145903056380374,418.5353798028726,60.09000974845256
5,7.358971054412516,280.60735160531476,250.58782523591074
4,7.543337862575298,318.62116642861554,368.5085377065596
2,0.37799481143106267,542.1714662545647,440.5577527410526
3,10.74018738983036,418.9643924672336,440.25854109974466
6,8.710530978872196,319.0430975366097,132.63080321008897
1,4.716853892332194,642.789415219967,368.4027616834399
2,1.0019810534766413,542.5609005814705,441.06203612756804
7,7.037294996766205,418.24699311081247,60.40061640760976
7,0.5432228877426432,419.1736431541566,60.013574541761756
6,16.235785269535214,318.2821454448339,132.76319058764352
8,10.99041820674714,542.4136740359763,59.88500420491323
4,7.798916414563655,319.0288604754668,368.0503200903666
6,7.395686325443695,318.81158982293607,132.6016639353577
6,18.275258256185857,318.5271147911616,132.46480538033506
0,2.8710507712945685,680.603203356266,250.76448760717176
7,7.760514100563604,418.48387544026525,60.285001259978145
2,9.424215674750943,541.9880334601559,441.1497093057435
4,5.005569190024609,318.3001056693673,367.86292593541003
7,10.035869374119926,418.51720316039325,60.08993371923569
1,3.8865898728352515,642.7683569196898,367.7784947793596
7,10.293318790683138,418.5320062724121,60.222430960956245
2,7.233085962035134,542.6898302744895,440.60510418821946
4,7.294801709580865,318.3460521244623,368.1742118255832
3,5.254472553733428,418.23238114320606,440.2534820207104
4,5.495118604610564,318.96154943184854,367.5764557135888
8,7.272187246653192,542.774772040947,60.57896031111591
5,6.987138494734555,280.1132306647487,250.51683337916623
4,5.609004479085082,318.639339774213,368.2245523751379
0,7.85039088981628,680.5493812658824,250.2790705950465
7,9.203129056006496,418.7204606822405,59.92684862481545
7,8.843972167702068,419.1624218333226,60.66844439993727

0 comments on commit d477885

Please sign in to comment.