Package installation

Package moonBook is avaiable on CRAN and github. Package moonBook2 is available only on github. Please install moonBook2 package using the following R code.

install.packages("devtools")
devtools::install_github("cardiomoon/moonBook")
devtools::install_github("cardiomoon/moonBook2")

Because functions in "moonBook2" make interactive plots using package "ggiraph", I strongly recommend you to install the latest version of the package "ggiraph" from github using following R command.

devtools::install_github("davidgohel/ggiraph")

In this vignette, I will show you how to use these functions. 1. ggPair() make an interactive scatterplot with line graph with wide form data.frame 2. ggPairLong() make an interactive scatterplot with line graph with long form data.frame 3. ggScatter() make an interactive scatterplot with linear regression

ggPair()

Basically, ggPair() function draws scatterplot with lineplot. It can be used to visualize paired test or repeated measures ANOVA.

require(ggplot2)
require(ggiraph)
require(moonBook2)

ggPair(iris,interactive=TRUE)

You can zoom-in and zoom-out the plots with your mouse wheel. You can flip the the x-axis and y-aix by setting the parameter horizontal TRUE.

ggPair(iris,horizontal=TRUE,interactive=TRUE)

If you select the two variables, the boxplot will be added.

ggPair(iris,vars=c("Sepal.Length","Sepal.Width"),interactive=TRUE)

You can use colorvar parameter to be assigened as a color variable.

ggPair(iris,vars=c("Sepal.Length","Sepal.Width"),colorvar="Species",interactive=TRUE)

In this plot, you are also able to make horizontal plot.

ggPair(iris,vars=c("Sepal.Length","Sepal.Width"),colorvar="Species",
       horizontal=TRUE,interactive=TRUE)

If a data.frame has two continuous variables, the boxplot added automatically.

ggPair(iris[3:5],colorvar="Species",horizontal=TRUE,interactive=TRUE)

ggPairLong()

If your data.frame is a long form, you can use ggPairLong().

require(reshape2)

iris$id=1:nrow(iris)
irislong=melt(iris[3:6],id=c("id","Species"))

ggPairLong(irislong,idvar="id",interactive=TRUE)
ggPairLong(irislong,idvar="id",colorvar = "Species",interactive=TRUE)

ggScatter()

ggScatter() draws interactive scatterplot with regression line. The basic method of regression is loess.

require(moonBook)
require(plyr)
ggScatter(radial,xvar="age",yvar="NTAV",interactive=TRUE)

If you select the regression method "lm", the regression equation will be appeared as a tooltip on the regression line.

ggScatter(radial,xvar="age",yvar="NTAV",method="lm",interactive=TRUE)

You can use colorvar or fillvar to differentiate groups.

ggScatter(radial,xvar="age",yvar="NTAV",colorvar="sex",interactive=TRUE)
ggScatter(radial,xvar="age",yvar="NTAV",fillvar="sex",interactive=TRUE,shape=21)
ggScatter(radial,xvar="age",yvar="NTAV",fillvar="sex",facetvar="DM",interactive=TRUE,shape=21)
ggScatter(radial,xvar="age",yvar="NTAV",colorvar="sex",fillvar="sex",facetvar="DM",method="lm",shape=21,interactive=TRUE)
ggScatter(radial,xvar="height",yvar="weight",colorvar="sex",facetvar="sex",interactive=TRUE)

You can use formula with ggScatter().

ggScatter(NTAV~age,data=radial,interactive=TRUE)
ggScatter(NTAV~age|smoking,data=radial,fullrange=TRUE,method="lm",se=FALSE,interactive=TRUE)
ggScatter(NTAV~age|DM,data=radial,fullrange=TRUE,method="lm",se=TRUE,interactive=TRUE)
ggScatter(NTAV~age|DM,facetvar="DM",data=radial,fullrange=TRUE,se=TRUE,interactive=TRUE)


cardiomoon/moonBook2 documentation built on May 13, 2019, 12:40 p.m.