-
Notifications
You must be signed in to change notification settings - Fork 1
/
plot_ussc_logo.R
77 lines (67 loc) · 3.43 KB
/
plot_ussc_logo.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
## Plot USSC logo on ggplot2 graph
## Zoe Meers
## The United States Studies Centre at the University of Sydney
#' Append new USSC logo at the bottom of graph
#' @usage
#' plot_ussc_logo()
#' @param ggplot_object A ggplot2 graph - either last_plot() or written out to a specific name.
#' @param position A character vector of the logo position - "bottom-right", "bottom-centre","bottom-center","bottom-left","top-right", "top-centre","top-center","top-left".
#' @examples
#' \dontrun{
#' graph <- ggplot2::ggplot2::ggplot(mtcars, ggplot2::aes(x = wt, y = mpg)) +
#' ggplot2::geom_point() +
#' ussc::theme_ussc()
#' plot_ussc_logo(ggplot_object = graph, position = "bottom-right")
#' }
#' @author
#' Zoe Meers
#' @export
plot_ussc_logo <- function(ggplot_object, position = "bottom-right"){
logo <- magick::image_read_svg(system.file("img/USSC_convert_positive.svg",
package = "ussc")) %>%
magick::image_chop("450x875+315") %>%
grid::rasterGrob(interpolate = TRUE)
if(position == "bottom-right"){
logo_plot <- ggplot2::ggplot(mapping = aes(x = 0:1, y = 1)) +
ggplot2::theme_void() +
ggplot2::annotation_custom(grob = logo, xmin = 0.85, xmax = 1.055)
gridExtra::grid.arrange(ggplot_object, logo_plot, heights = c(0.93,
0.1))
} else if(position == "bottom-left") {
logo_plot <- ggplot2::ggplot(mapping = aes(x = 0:1, y = 1)) +
ggplot2::theme_void() +
ggplot2::annotation_custom(grob = logo, xmin = 0, xmax = 0.205)
gridExtra::grid.arrange(ggplot_object, logo_plot, heights = c(0.93,
0.1))
} else if(position == "top-left") {
logo_plot <- ggplot2::ggplot(mapping = aes(x = 0:1, y = 1)) +
ggplot2::theme_void() +
ggplot2::annotation_custom(grob = logo, xmin = 0, xmax = 0.205)
gridExtra::grid.arrange(logo_plot, ggplot_object, heights = c(0.1, 0.93))
} else if(position == "top-right") {
logo_plot <- ggplot2::ggplot(mapping = aes(x = 0:1, y = 1)) +
ggplot2::theme_void() +
ggplot2::annotation_custom(grob = logo, xmin = 0.85, xmax = 1.055)
gridExtra::grid.arrange(logo_plot, ggplot_object, heights = c(0.1, 0.93))
} else if(position == "top-centre") {
logo_plot <- ggplot2::ggplot(mapping = aes(x = 0:1, y = 1)) +
ggplot2::theme_void() +
ggplot2::annotation_custom(grob = logo, xmin = 0.45, xmax = 0.655)
gridExtra::grid.arrange(logo_plot, ggplot_object, heights = c(0.1, 0.93))
} else if(position == "top-center") {
logo_plot <- ggplot2::ggplot(mapping = aes(x = 0:1, y = 1)) +
ggplot2::theme_void() +
ggplot2::annotation_custom(grob = logo, xmin = 0.45, xmax = 0.655)
gridExtra::grid.arrange(logo_plot, ggplot_object, heights = c(0.1, 0.93))
} else if(position == "bottom-center") {
logo_plot <- ggplot2::ggplot(mapping = aes(x = 0:1, y = 1)) +
ggplot2::theme_void() +
ggplot2::annotation_custom(grob = logo, xmin = 0.45, xmax = 0.655)
gridExtra::grid.arrange(ggplot_object, logo_plot, heights = c(0.93, 0.1))
} else if(position == "bottom-centre") {
logo_plot <- ggplot2::ggplot(mapping = aes(x = 0:1, y = 1)) +
ggplot2::theme_void() +
ggplot2::annotation_custom(grob = logo, xmin = 0.45, xmax = 0.655)
gridExtra::grid.arrange(ggplot_object, logo_plot, heights = c(0.93, 0.1))
}
}