setwd('/Users/rwoldford/Documents/Admin/gradstudents/AdrianWaddell/Japan') load('gapminderData.rda') ## Interaction library(RnavGraph) library(RnavGraphImageData) library(PairViz) V <- c("Age","Suic","Frtly","Trdeath","Murder","Mort") G <- completegraph(V) LG <- linegraph(G) LGnot <- complement(LG) ng.gap <- ng_data("GapMinder", as.data.frame(gapminderData[,-1]),shortnames=V,labels=gsub(" ","_",as.character(gapminderData$Country))) ng.lg <- ng_graph(name="3D transitions", LG, layout="circle") ng.lgnot <- ng_graph(name="4D transitions", LGnot, layout="circle") glyphs <- as.vector(apply(hpaths(names(ng.gap)),1, FUN = function(x){x})) imgPath <- system.file("worldflags_small", package="RnavGraphImageData") flag_country <- list.files(path=imgPath, full.names=FALSE) f <- tolower(gsub("\\..{3,4}$",'',flag_country)) ## Remove m <- match(gsub(" ","_",tolower(gapminderData$Country), fixed = TRUE),f) flag_images <- list.files(path=imgPath, full.names=TRUE)[m] ng.i.flags <- ng_image_files(name="flags", path=flag_images) nav <- navGraph(ng.gap, list(ng.lg,ng.lgnot), list(ng_2d(ng.gap,ng.lg, glyphs = glyphs,images=ng.i.flags), ng_2d(ng.gap,ng.lgnot, glyphs = glyphs,images=ng.i.flags))) ## myfaces library(rJava) gapminderDataN <- apply(gapminderData[,c(2:7)],2,function(x){(x-min(x))/diff(range(x))}) ## init Java .jinit() # this starts the JVM .jaddClassPath("chernoff.jar") win <<- .jnew("builder/ChernoffScatterplot",50L) ## Java internally draws the faces and stores it in a image vector which ## later with updateXY will be drawn apply(gapminderDataN,1,function(row){ .jcall(win, "V","addFace",round(row[c(2,3,7,5,6,4)-1]*100)) }) viz3 <- ng_2d_myplot(ng.gap, ng.lg, fnName = "myFace", device = NULL, scaled = TRUE) myFace <<- function(x,y) { .jcall(win, "V","updateXY",(y/1 +0.2),(x/1+0.2)) } nav <- navGraph(ng.gap, ng.lg, viz3)