#' PERU theme for all plots in presentation
#'
#' @param method Which method was used to differ variables in a plot? Two possible value: color or fill.(Have to be the same method as used in ggplot phrase).
#' @param legend_title Title of legend. Default value: "Legend"
#' @param color Which color group we want to implement? Four possible group: categorical colors,diverging_colors, sequential colors or any other color vector. Default value: categorical_colors
#' @param fig_number Number of figures. Default value = "".
#' @param font Font used in the plot. Devault value: font = "Open Sans"
#' @param axis_title_size Size of title of axis. Default size: 22.
#' @param axis_text_size Size of value of axis. Default size: 17.
#' @param xtext_slope Slope of value of x axis (in degree). Default slope value: 0.
#' @param xtext_position Useful when xtext_slope != 0 (then this argument should be = 1). Distance between text and plot border. Default value: 0.5.
#' @param legend_object_size Size of object in legend. Default falue: 1.2
#' @param legend_text_size Size of text inside legend. Defalut size: 14.
#' @param legend_title_size Size of legend title. Default size: 13.
#' @examples
#' \dontrun{
#' ggplot(mtcars, aes(factor(cyl), wt))+
#' geom_bar(stat = "identity", fill = cat_colors[1])+
#' theme_peru()+
#' draw_scale_numeric("y",0,60)
#'
#' ggplot(diamonds[1:100,], aes(depth, carat, color = factor(cut)))+
#' geom_point(size = 7)+
#' theme_peru("color")+
#' draw_scale_numeric("y",0,1,0.1,labels_percent = T)
#' }
theme_peru <- function(method = "color",
legend_title = "Legend",
color = cat_colors,
fig_number = "",
font = "Open Sans",
axis_title_size = 22,
axis_text_size = 17,
xtext_slope = 0,
xtext_position = 0.5,
legend_object_size = 1.2,
legend_text_size = 14,
legend_title_size = 13){
list(
ggtitle(fig_number),
draw_scale_manual(method, color, legend_title),
theme(
text = element_text(colour = 'black', family = font),
rect = element_rect(color = 'black'),
axis.text = element_text(size = axis_text_size),
axis.text.x = element_text(angle = xtext_slope, hjust = xtext_position),
axis.text.y = element_text(vjust = 0.5, hjust = 1, angle = 0),
axis.ticks = element_line(colour = "black", size = 0.6),
axis.ticks.length = unit(axis_text_size/4, "pt"), #new
axis.title = element_text(size = axis_title_size, face = "bold"),
axis.title.x = element_text(margin = margin(t = 0.5 * axis_title_size)),
axis.title.y = element_text(margin = margin(r = 0.7 * axis_title_size)),
legend.key = element_blank(),
legend.key.size = unit(legend_object_size, "cm"),
legend.text = element_text(size = legend_text_size),
legend.title = element_text(size = legend_title_size, face = 'bold'),
panel.background = element_rect(fill = "#F9FBFF"),
panel.border = element_rect(fill = NA, size = 0.8),
panel.grid.major = element_line(colour = "grey88"),
panel.grid.minor = element_line(colour = "grey93"),
plot.title = element_text(margin = margin(t = 4, b = 1.5), hjust = 1, size = 8, colour = 'gray95'),
plot.margin = margin(3, 12, 18, 16),
strip.background = element_rect(fill = "#C6DBEF", size = 1.2),
strip.text = element_text(size = axis_text_size)
)
)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.