Package moonBook
is available 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 "ggplot2" and "ggiraph", I strongly recommend you to install the latest version of the package "ggplot2" and "ggiraph" from github using following R command.
devtools::install_github("hadley/ggplot2") devtools::install_github("davidgohel/ggiraph")
In this vignette, I will show you how to use t
hese functions. 1. ggCor() make an interactive correlation plot 2. ggBoxplot() make an interactive boxplot of a data.frame 3. ggScatter() make an interactive scatterplot with linear regression
ggCor() function draws a heatmap showing the correlation coefficients of a data.frame.
require(ggplot2) require(ggiraph) require(moonBook2) require(mycor) ggCor(mtcars,interactive=TRUE)
You can zoom-in and zoom-out the plots with your mouse wheel. You can label the r values on the heatmap.
ggCor(mtcars,label=TRUE,interactive=TRUE)
You can change the colors of heatmap by using the color argument.
ggCor(mtcars,colors=c("red","white","blue"),interactive=TRUE)
ggBoxplot() draws boxplots of all numeric variables in a data.frame. You can use this plot for navigate the outliers in a dataframe.
ggBoxplot(iris,interactive=TRUE)
You can make a horizontal boxplot by setting the horizontal argument TRUE.
ggBoxplot(mtcars,horizontal=TRUE,interactive=TRUE)
You can rescale the variables by setting the rescale argument TRUE.
ggBoxplot(mtcars,rescale=TRUE,horizontal=TRUE,interactive=TRUE)
You can change the theme.
p<-ggBoxplot(mtcars,horizontal=TRUE)+theme_bw() ggiraph(code=print(p),zoom_max=10)
ggScatter() draws interactive scatterplot with regression line. By default, loess regression line(s) are added to plot.
require(moonBook) ggScatter(radial,xvar="height",yvar="weight",interactive=TRUE)
If you want to fit a linear regression model, set the method argument "lm". You can see the regression formula with hovering your mouse on the regression line.
ggScatter(radial,xvar="height",yvar="weight",method="lm",interactive=TRUE)
You can use colorvar to diffentiate groups.
ggScatter(radial,xvar="height",yvar="weight",colorvar="sex",method="lm",interactive=TRUE)
You can get faceted plots by setting the argument facet TRUE.
ggScatter(radial,xvar="height",yvar="weight",colorvar="sex",facet=TRUE,method="lm",interactive=TRUE)
You can use formula to obtain seperate regression lines.
ggScatter(NTAV~age|smoking,data=radial,fullrange=TRUE,method="lm",se=FALSE,interactive=TRUE)
You can make faceted plots using continuous variables. If you select a continuous variable as the "colorvar" and set the facet TRUE, You can get faceted plot.
ggScatter(acs,yvar="weight",xvar="height",colorvar="age",method="lm",facet=TRUE,interactive=TRUE)
You can use a continuous variable as the "colorvar" without faceting.
ggScatter(acs,yvar="weight",xvar="height",colorvar="age",method="lm",interactive=TRUE)
You can changed the number of facets by setting the cut_number parameter.
ggScatter(acs,yvar="weight",xvar="height",colorvar="age",cut_number=4,method="lm",facet=TRUE,interactive=TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.