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")
In this vignette, I will show you how to use these functions.
You can’t make a population pyramid without data; PopPyramid() function gets population data data from US Census Bereau. This function uses get_popdata() function internally and this function is a modification of get_data() function of Kyle Walker's. You can use PopPyramid function with the following format.
PopPyramid(country,year,interactive=FALSE)
The country parameter shoud be one of the FIPS 10-4 country code. If you wnated to make a population pyramid 2016 for Nigeria, you can use the following code.
require(moonBook2) require(ggplot2) require(ggiraph) require(moonBook) PopPyramid("NI",2016,interactive=TRUE)
The followings are other examples.
PopPyramid("KS",2016,interactive=TRUE) # for South Korea PopPyramid("US",2016,interactive=TRUE) # for United States
You can make interactive barplot by ggBar().
ggBar(acs,"Dx","smoking",interactive=TRUE)
You can add labels to barplot easily by setting the parameter addlabel=TRUE
ggBar(acs,"Dx","smoking",addlabel=TRUE,interactive=TRUE) ggBar(acs,"Dx","smoking",position="dodge",addlabel=TRUE,interactive=TRUE) ggBar(acs,"Dx","smoking",position="fill",addlabel=TRUE,interactive=TRUE)
You can make horizontal bar plot easily by setting the parameter horizontal=TRUE ````r ggBar(acs,"Dx","smoking",position="fill",addlabel=TRUE,horizontal=TRUE,yangle=90, width=0.5,interactive=TRUE)
You can make polar map by setting the parameter polar=TRUE ```r ggBar(acs,"Dx","smoking",interactive=TRUE,width=1,colour="white",size=0.2,polar=TRUE)
You can make barplot from preprocessed data.
ggBar(rose,Month,group,"value",stat="identity",interactive=TRUE)
You can make rose plot by using ggBar().
ggBar(rose,Month,group,"value",stat="identity",polar=TRUE,palette="Reds",width=1, color="black",size=0.1,interactive=TRUE)
You can make rose plot more easily by using ggRose()
ggRose(rose,Month,group,"value",interactive=TRUE)
Here comes another example of ggRose().
ggRose(acs,"Dx","smoking",interactive=TRUE)
In heatmap, you can assign a continuous variable to the fill
color. You can make interactive heatmap by using ggHeatmap()
ggHeatmap(acs,"Dx","smoking",interactive=TRUE)
You can add labels to heatmap easily by setting the parameter addlabel=TRUE
ggHeatmap(acs,"Dx","smoking",addlabel=TRUE,interactive=TRUE)
You can make heatmap with preprocessed data.
ggHeatmap(rose,"group","Month","value",stat="identity",interactive=TRUE)
You can change the fill colors by seting the parameter gradient_colors()
ggHeatmap(rose,"group","Month","value",stat="identity",gradient_colors = c("white","red"),interactive=TRUE)
You can make polar heatmap by seting the parameter polar TRUE.
ggHeatmap(rose,"Month","group","value",stat="identity",polar=TRUE,interactive=TRUE)
Another example comse from taco data. This data is made by "Aaron Richter". Please take a look at one of his wonderful post Communicating Experimental Results with R.
head(taco) str(taco)
This data consisits of ratings of taco by shell types, age groups and filllings. You can make heatmap with this data.
ggHeatmap(taco,"AgeGroup","Filling","Rating",stat="identity",interactive=TRUE)
You add facets to you heatmap.
ggHeatmap(taco,"AgeGroup","Filling","Rating",facetvar="ShellType", stat="identity",interactive=TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.