ggplot2_theme.R 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. # library(extrafont)
  2. library(showtext)
  3. font_add(family = "Helvetica", regular = "Helvetica.ttf")
  4. showtext_auto()
  5. library(svglite)
  6. axis_linewidth <- 0.4
  7. theme_set(
  8. theme_classic(base_family = "Helvetica") +
  9. theme(
  10. plot.title = element_text(size=10, hjust=0.5),
  11. text = element_text(size=8, family="Helvetica", colour="black"),
  12. plot.tag = element_text(face="bold", size=10),
  13. plot.margin = margin(1,2,1,2, "pt"),
  14. axis.line = element_line(colour = "black", linewidth=axis_linewidth),
  15. axis.ticks = element_line(colour = "black", linewidth=axis_linewidth),
  16. axis.text = element_text(colour="black", size=8),
  17. legend.text = element_text(colour="black", size=8),
  18. legend.title = element_text(colour="black", size=9),
  19. axis.title = element_text(colour="black", size=9),
  20. strip.background = element_blank(),
  21. strip.text = element_text(size = 9)
  22. )
  23. )
  24. # measure_cols <- c("Jaccard Distance"="#CD8A00", "Wasserstein Distance"="#0043CD")
  25. measure_cols <- c("Jaccard Distance"="#eb6c00ff", "Wasserstein Distance"="#2b73bcff")
  26. measure_cols_light_rgb <- col2rgb(measure_cols) * 0.4 + matrix(rep(255, 6), nrow=3) * 0.6
  27. measure_cols_light <- apply(measure_cols_light_rgb, MARGIN=2, function(x) rgb(t(x), maxColorValue=255))
  28. # function for interpolating between two colours with n equally spaced colours
  29. interpolate_hex <- function(a, b, n=4) {
  30. k <- seq(0, 1, length.out=n)
  31. a_cols <- matrix(rep(col2rgb(a), n), ncol=n)
  32. b_cols <- matrix(rep(col2rgb(b), n), ncol=n)
  33. k_cols <- t(matrix(rep(k, 3), nrow=n))
  34. c_cols <- a_cols * k_cols + b_cols * (1-k_cols)
  35. apply(c_cols, MARGIN=2, function(x) rgb(t(x), maxColorValue=255))
  36. }