package ggiraphExtra

Keon-Woong Moon

2020-10-06

Package ggiraphExtra contains many useful functions for exploratory plots. These functions are made by both ‘ggplot2’ and ‘ggiraph’ packages. You can make a static ggplot or an interactive ggplot by setting the parameter interactive=TRUE.

Package installation

You can install package ggiraphExtra with the following command.

#install.packages("devtools")
devtools::install_github("cardiomoon/ggiraphExtra")

ggPoints() for interactive scatterplot with regression equation

You can make interactive ggplot easily. You can hover the points, see the regression equations and zoom-in zoom-out with the mouse wheel.

require(ggplot2)
require(ggiraph)
require(ggiraphExtra)

ggPoints(aes(x=wt,y=mpg,color=am),data=mtcars,method="lm",interactive=TRUE)
10 20 30 2 3 4 5 wt mpg am 0 1 smoothing method=lm

You can draw scatter plot for binary dependent variable. The GBSG2 data contains data of 686 observations from the German Breast Cancer Study Group 2(GBSG2) study. You can get logistic regression line with a jittered scatterplot by setting the parameter method glm.

require(TH.data)
data(GBSG2)
ggPoints(aes(x=pnodes,y=cens),data=GBSG2,method="glm",interactive=TRUE)
0.0 0.3 0.6 0.9 0 10 20 30 40 50 pnodes cens smoothing method=glm

Please check the vignette for “ggPoints” at http://rpubs.com/cardiomoon/231822

ggRadar() for interactive radar chart

You can explore a data.frame with ggRadar() or ggBoxplot().

ggRadar(data=iris,aes(color=Species),interactive=TRUE)
Sepal.Length Sepal.Width Petal.Length Petal.Width 0.2 0.4 0.6 0.8 Species setosa versicolor virginica
ggRadar(data=mtcars,aes(colour=am),interactive=TRUE)
mpg cyl disp hp drat wt qsec vs gear carb 0.2 0.4 0.6 am 0 1

ggSpine() for an interactive spinogram

ggSpine() is a interactive ggplot version of spineplot(). Spine plots are a special cases of mosaic plots, and can be seen as a generalization of stacked (or highlighted) bar plots. Analogously, spinograms are an extension of histograms. You can add labels by setting the parameter addlabel=TRUE.

require(moonBook)
ggSpine(data=acs,aes(x=age,fill=smoking),interactive=TRUE)
16.70% 19.40% 63.90% 20.60% 32.40% 47.10% 17.60% 18.60% 63.70% 17.10% 40.50% 42.30% 29.00% 35.90% 35.10% 22.80% 44.90% 32.40% 29.10% 51.80% 19.10% 27.90% 53.50% 18.60% 37.50% 42.50% 20.00% Ex-smoker Never Smoker 40 45 50 55 60 65 70 75 80 85 age smoking
ggSpine(data=acs,aes(x=Dx,fill=smoking),addlabel=TRUE,interactive=TRUE)

27.50% 32.70% 39.90% 21.70% 31.90% 46.40% 24.00% 46.20% 29.80% Ex-smoker Never Smoker NSTEMI STEMI Unstable Angina Dx smoking
## ggBar() for an interactive barplot

ggBar() draws interactive barplot. You can add labels, draw horizontal barplots or polar plots. You can draw histogram with ggBar()

ggBar(acs,aes(x=Dx,fill=smoking),addlabel=TRUE,horizontal=TRUE,width=0.5,interactive=TRUE)
42 50 61 66 97 141 96 185 119 NSTEMI STEMI Unstable Angina 0 100 200 300 400 count Dx smoking Ex-smoker Never Smoker
ggBar(rose,aes(x=Month,fill=group,y=value),stat="identity",polar=TRUE,palette="Reds",width=1,
       color="black",size=0.1,interactive=TRUE)
January February March April May June July August September October November December 0 20 40 60 Month count group A B C D E F G
ggBar(acs,aes(x=age,fill=smoking),addlabel=TRUE,horizontal=TRUE,width=0.5,interactive=TRUE)
1 0 0 1 0 0 0 0 2 0 0 2 0 0 4 0 0 3 0 1 2 0 2 5 3 1 7 0 1 4 0 1 4 3 0 7 0 4 1 2 3 5 3 5 7 1 3 10 7 8 6 1 3 4 2 4 17 7 3 9 4 4 13 5 3 5 0 5 21 4 9 11 3 10 11 3 9 11 4 10 7 5 7 7 8 12 13 7 8 11 5 4 6 9 9 8 9 14 8 8 8 8 6 12 11 7 11 9 7 11 6 3 19 10 4 15 3 6 9 6 8 10 4 7 11 2 7 12 6 3 10 3 11 5 4 6 13 2 1 9 5 3 9 2 8 6 4 3 4 1 2 1 1 1 2 1 1 4 1 0 4 0 1 2 0 3 1 0 0 1 0 1 0 0 0 0 1 40 60 80 0 10 20 30 count age smoking Ex-smoker Never Smoker

ggPair() for an interactive scatter plot with line plot

ggPair(iris[3:5],interactive=TRUE)
0 2 4 6 Petal.Length Petal.Width
ggPair(iris,aes(color=Species),horizontal=TRUE,interactive=TRUE)
Sepal.Length Sepal.Width Petal.Length Petal.Width Species 0 2 4 6 8 Species setosa versicolor virginica

ggPieDonut() for a pie and donut plot

You can draw a pie and donut plot with ggPieDonut().

ggPieDonut(acs,aes(pies=Dx,donuts=smoking),interactive=TRUE)
Ex-smoker (4.9%) Never (5.8%) Smoker (7.1%) Ex-smoker (7.7%) Never (11.3%) Smoker (16.5%) Ex-smoker (11.2%) Never (21.6%) Smoker (13.9%) NSTEMI (17.9%) STEMI (35.5%) Unstable Angina (46.7%)
ggPieDonut(browsers,aes(pies=browser,donuts=version,count=share),interactive=TRUE)
MSIE 6.0 (11.8%) MSIE 7.0 (8%) MSIE 8.0 (36%) MSIE 9.0 (3.1%) Firefox 3.5 (1.7%) Firefox 3.6 (14.3%) Firefox 4.0 (5.9%) Chrome 10.0 (10.8%) Safari 4.0 (1.5%) Safari 5.0 (5%) Opera 11.x (1.8%) MSIE (58.9%) Firefox (21.9%) Chrome (10.8%) Safari Opera
ggDonut(browsers,aes(donuts=version,count=share),interactive=TRUE)
MSIE 6.0 (11.8%) MSIE 7.0 (8%) MSIE 8.0 (36%) MSIE 9.0 (3.1%) Firefox 3.5 (1.7%) Firefox 3.6 (14.3%) Firefox 4.0 (5.9%) Chrome 10.0 (10.8%) Safari 4.0 (1.5%) Safari 5.0 (5%) Opera 11.x (1.8%)

ggCLE() for a cleveland dot plot

require(gcookbook)
mtcars$name=rownames(mtcars)
ggCLE(data=mtcars,aes(x=mpg,y=name,color=am,facet=am),interactive=TRUE)
0 1 10 15 20 25 30 35 Mazda RX4 Mazda RX4 Wag Datsun 710 Hornet 4 Drive Hornet Sportabout Valiant Duster 360 Merc 240D Merc 230 Merc 280 Merc 280C Merc 450SE Merc 450SL Merc 450SLC Cadillac Fleetwood Lincoln Continental Chrysler Imperial Fiat 128 Honda Civic Mazda RX4 Mazda RX4 Wag Datsun 710 Hornet 4 Drive Hornet Sportabout Valiant Duster 360 Merc 240D Merc 230 Merc 280 Merc 280C Merc 450SE Merc 450SL mpg
ggCLE(data=tophitters2001,aes(x=avg,y=name,color=lg,facet=lg),no=20,interactive=TRUE)
AL NL 0.32 0.33 0.34 0.35 Larry Walker Ichiro Suzuki Jason Giambi Roberto Alomar Todd Helton Moises Alou Lance Berkman Larry Walker Ichiro Suzuki Jason Giambi Roberto Alomar Todd Helton Moises Alou Lance Berkman Bret Boone Frank Catalanotto Chipper Jones Albert Pujols Barry Bonds Sammy Sosa avg

Full version of this vignette

You can find the full version of this vignette at http://rpubs.com/cardiomoon/231820