├── News.md ├── README.md └── themes.R /News.md: -------------------------------------------------------------------------------- 1 | 2 | ## 18/01/2016 3 | 4 | Some changes have been made to make the theme behave a bit better and to be consistent with v. 2 of ggplot2. 5 | 6 | 1. plot_type has been removed as an option. It was really just letting you do something that could be done easily anyway. 7 | 2. The ability to easily remove axis ticks has been added with the ticks_xy option. 8 | 3. ticks_type has been changed because axis.ticks.margin is being deprecated. 9 | 4. ticks_length is no longer something that can be modified. 10 | 5. Some minor aesthetic changes have been made to make the defaults look a bit better. 11 | 12 | 13 | ## 9/10/2015 14 | 15 | theme_agile is now updated in response to some of the feedback after I put it on GitHub a week ago. 16 | 17 | 1. I have switched from . to _ in the theme options to be consistent. Having base_size and plot.type was probably confusing. 18 | 19 | 2. The base fone size has been switched to 11 to match the default ggplot2 size. 20 | 21 | 3. I have added in an option (grid_thick) to make grid lines thinner or thicker. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ggplot2-theme 2 | a ggplot2 designed to make it easier to create publication quality figures 3 | -------------------------------------------------------------------------------- /themes.R: -------------------------------------------------------------------------------- 1 | # Theme used to create journal ready figures easilys 2 | # 3 | # base_size Font size 4 | # base_family Font used for everything, unless axis fonts etc. are defined 5 | # lines_lwd = width of lines 6 | # plot_grid = Do you want a grid? 7 | # font_type Font type 8 | # title_size = font size of title 9 | # legend_size = font size of legend 10 | # bg_col = background colour 11 | # title_font = font use for title 12 | # base_col = font colour 13 | # horz_grid = Do you want a horizontal grid? 14 | # bord_size = width of a rectangular border 15 | # alpha_leg = opacity of the legend. 0 = totally transparent 16 | # strip_bg = colour background for facets 17 | # grid_thick = A multiplier to apply to the grid lines. 0.8 would reduce thickness by 20% 18 | # grid_type = Grid type. Default is a solid line 19 | # ticks_xy = Do you want ticks on the x or y axis? "x" = x-axis only, "y" = y-axis only, "xy" = both axes. 20 | # grid_cols = Colour of the grid. 2 element vector. First element is major grid colour. If only one element, the first will be used for minor grid. 21 | 22 | 23 | 24 | theme_agile <- function(base_size = 11, base_family = "Arial", lines_lwd = 0.50, plot_grid = TRUE, axis_font = base_family, title_size = base_size*1.2, legend_size = base_size, 25 | bg_col = "white",title_font = base_family , base_col = "black", axis_lines = TRUE, 26 | minor_grid = ifelse(plot_grid, TRUE, FALSE), vert_grid = ifelse(plot_grid, TRUE, FALSE), ticks_type = "outer", horz_grid = ifelse(plot_grid, TRUE, FALSE), alpha_leg = 0.1, bord_size = 0, 27 | legend_bg = "white", strip_bg = "white", grid_thick = 1, 28 | grid_type = "solid", ticks_xy = "xy", grid_cols = c("grey50", "grey70")){ 29 | theme_bw()+ 30 | ggplot2::theme( 31 | plot.margin = grid::unit(c(1, 1, .5, .7), "cm"), 32 | text = ggplot2::element_text(family = base_family, size = base_size), 33 | axis.line = element_line(size = ifelse(axis_lines, grid::unit(lines_lwd, "mm"),0), color = "black"), 34 | axis.ticks.length = grid::unit(ifelse(ticks_type == "outer", 0.15, -0.15), "cm"), 35 | axis.ticks.x = element_line(size = ifelse(stringr::str_detect(ticks_xy, "x"), grid::unit(lines_lwd, "cm"),0), color = "black"), 36 | axis.ticks.y = element_line(size = ifelse(stringr::str_detect(ticks_xy, "y"), grid::unit(lines_lwd, "cm") ,0), color = "black"), 37 | axis.text.x = ggplot2::element_text(size = base_size, colour = base_col , family = axis_font,margin=margin(ifelse(ticks_type == "inner", 11, 5),5,10,5,"pt")), 38 | axis.text.y = ggplot2::element_text(size = base_size, colour = base_col , family = axis_font, margin=margin(5,ifelse(ticks_type == "inner", 11, 5),10,5,"pt")), 39 | axis.title.y = ggplot2::element_text(size = base_size, colour = base_col , vjust = 1.5, family = axis_font), 40 | axis.title.x = ggplot2::element_text(size = base_size,colour = base_col ,vjust = -.5, family = axis_font), 41 | panel.background = ggplot2::element_rect(fill = bg_col), 42 | plot.background = ggplot2::element_rect(fill = bg_col), 43 | panel.border = ggplot2::element_rect(colour = "black", fill=NA, size = bord_size), 44 | panel.grid.major.x = ggplot2::element_line(linetype = grid_type,colour = ifelse(vert_grid, grid_cols[1],bg_col), size = ifelse(vert_grid,0.25 * grid_thick, 0)), 45 | panel.grid.minor.x = ggplot2::element_line(linetype = grid_type,colour = ifelse(vert_grid, ifelse(minor_grid, grid_cols[2 - (length(grid_cols) == 1) ],bg_col),bg_col), size = ifelse(vert_grid,0.15* grid_thick, 0)), 46 | panel.grid.major.y = ggplot2::element_line(linetype = grid_type,colour = ifelse(horz_grid, grid_cols[1],bg_col), size = ifelse(horz_grid,0.25* grid_thick, 0)), 47 | panel.grid.minor.y = ggplot2::element_line(linetype = grid_type,colour = ifelse(horz_grid, ifelse(minor_grid, grid_cols[2 - (length(grid_cols) == 1) ],bg_col),bg_col), size = ifelse(horz_grid,0.15* grid_thick, 0)), 48 | plot.title = ggplot2::element_text(face="bold",vjust = 2, colour = base_col , size = title_size, family = title_font), 49 | legend.background = ggplot2::element_rect(fill = scales::alpha(legend_bg, alpha_leg)), legend.key = ggplot2::element_blank(), 50 | legend.text = ggplot2::element_text(size = legend_size, family = base_family), 51 | legend.title = element_blank(), 52 | strip.background = ggplot2::element_rect(colour = strip_bg, fill = strip_bg), 53 | strip.text.x = ggplot2::element_text(size = base_size + 1), 54 | strip.text.y = ggplot2::element_text(size = base_size + 1) 55 | ) 56 | } 57 | --------------------------------------------------------------------------------