#' Visualization tool for number of complaints by any category.
#'
#' It displays a rotated barplot that features the categorical variables on the y axis, and values for the number of count of complaints on the x axis.
#'
#' The function can only take the specific dataframes generated by the other functions in this package that has two columns. The first column can feature any categorical labels, while the second column needs to contain values. The function will then take the dataframe and visualize the contents on a tailored barplot.
#'
#' @param df Dataframe (two columns)
#' @param limit Places a limit on the output of the barplot in terms of number of datapoints/ observations
#' @return Barplot with the same labels and values from the original dataframe
#' @author Jae Woong Ham
#' @import httr
#' @import rjson
#' @import ggplot2
#' @import maps
#' @import sp
#' @import maptools
#' @import stringr
#' @import magrittr
#' @import rvest
#' @import dplyr
#' @import forcats
#' @export
#' @examples
#' visualization_tool_function()
visualization_tool_function <- function(df=sampledf,limit=10){
sampledf <- data.frame("x" = c("sample1","sample2","sample3"), "y" = c(5,12,25))
df <- as.data.frame(df)
df <- head(df,limit)
df %>%
mutate(Category = fct_reorder(df[,1], as.numeric(as.character(df[,2])))) %>%
ggplot(aes(x=Category,y=as.numeric(as.character(df[,2]))))+
geom_col(fill="steelblue")+
geom_text(aes(label=as.numeric(as.character(df[,2]))), vjust=-0.3, size=3.5)+
coord_flip()+
xlab("")+
ylab("Count of Complaints")+
theme_minimal()
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.