#' Create line of with eigenvector centrality for nodes over time
#'
#' @param .eigen.centr.over.years a df that contains nodes and their centrality in a given year
#' @param .filename
#'
#' @return a line chart as ggplot object.
#' Eigenvector centrality was converted to NA if there was no exhibition before or after a given year.
#' Consequently, the line chart only shows centrality of an exhibition place during exhibition activity.
#' Moreover,
#' @export
#'
#' @examples
#' g <- create_example_graph()
#' centr.over.years <- compute_eigen_centr_period(g, 1995, 2002)
#'
#' plot_eigen_centr_over_years(centr.over.years)
plot_ecoy <- function(.eigen.centr.over.years, .filename = NULL){
plot <- ggplot(.eigen.centr.over.years) +
# create basic line chart
geom_line(aes(x = yr_centr_computed, y = eigen_centr, group = name_exhplace),
color = alpha("grey", 0.8)) +
# add color for top nodes according to eigenvector centrality from complete graph
geom_line(aes(x = yr_centr_computed, y = eigen_centr, color = name_exhplace),
data = .eigen.centr.over.years %>%
filter(eigen_centr >= 0.95) %>%
distinct(name) %>%
left_join(.eigen.centr.over.years, by = "name")) +
# customize layout
theme_minimal() +
labs(x = "Year", y = "Eigenvector Centrality", color = "Exhibition Venue") +
# remove left and right margin from plot
scale_x_continuous(expand = c(0,0), breaks = seq(1905, 2015, 10)) +
# highlighted exhibition venues should be displayed in columns
guides(color = guide_legend(ncol = 2, byrow = T)) +
theme(
# reduce text size
legend.text = element_text(size = 8.5),
# replace legend from right to bottom
legend.position = "bottom",
# reduce vertical and add horizontal spacing
legend.key.height = unit(0.7, 'lines'),
legend.key.width = unit(1.5, 'lines'),
# exclude varible name
legend.title = element_blank()
)
# save plot to drive
if(!is.null(.filename)){
ggsave(.filename, plot,
width = 7, height = 5)
}
return(plot)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.