#' Missing value pattern
#'
#' @param design "survey.design2" object of svydesign() from 'survey' package
#' @param plot logical. whether to plot
#'
#' @return
#' @export
#'
svy_missValue <- function(design,plot=TRUE){
ck <- sapply(design$variables,function(i) sum(is.na(i)))
ck <- ck[ck>0]
percent <- paste0(ck,'(',round(ck/nrow(design$variables),4)*100,'%)')
d <- data.frame(variable = names(ck),value=ck/nrow(design$variables),percent=percent)
if (plot){
ggplot(d,aes(y=variable))+
geom_bar(aes(weight=value))+
theme(
axis.line = element_blank(),
axis.ticks = element_blank(),
axis.title = element_blank(),
axis.text.x = element_blank()
)+
scale_x_continuous(limits = c(0,1.2),expand = c(0,0))+
geom_text(aes(label = percent),stat = 'count',colour = 'royalblue')
}else{
row.names(d) <- NULL
d
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.