Bin summary by covariate
summary_plot.Rd
Drawing a bin summary plot of covariates given an nethist
object with an user-specified order.
Usage
summary_plot(
object,
covariate,
idx_order = 1:max(object$cluster),
main = NA,
ylab = NA,
legend_title = NA,
stat = "count",
position = "stack"
)
Arguments
- object
a nethist object from
nethist()
.- covariate
a vector for univariate covariate. If it is factor, draw a stacked barchart. If it is numeric, draw a violin plot.
- idx_order
A numeric vector for index label order, which must be a permutation of
object$cluster
. IfNA
, it uses1:max(object$clsuter)
.- main
title of summary plot. If NA, the plot has no title.
- ylab
label of y-axis. If NA, y-axis label is "covariate"
- legend_title
title of legend. If NA, the legend title is "covariate"
- stat
variable pass to
ggplot2::geom_bar()
. Only used for a factor covariate.- position
variable pass to
ggplot2::geom_bar()
. Only used for a factor covariate.
Details
... includes various graphical parameters
passes to stats::heatmap()
, then graphics::image()
.
Examples
if (FALSE) {
set.seed(42)
nethist_polblog <- nethist(polblog, h = 72)
#Add factor covariate
politic <- factor(c(rep("Liberal", 586), rep("Conservative", 1224-586)))
summary_plot(nethist_polblog, politic)
#with user-specified order
idx <- c(17,10,13,7,12,4,8,5,1,2,6,3,9,15,11,14,16)
summary_plot(nethist_polblog, politic, idx_order = idx)
#Add title and change ylab
summary_plot(nethist_polblog, politic, idx_order = idx,
main = "Political View", ylab = "Number of blogs")
#Add numeric covariates
numeric_covariate <- nethist_polblog$cluster + rnorm(1224, sd = 3)
summary_plot(nethist_polblog, numeric_covariate)
summary_plot(nethist_polblog, numeric_covariate, idx_order = idx) #With-user specified order
}