/
excel.R
131 lines (122 loc) · 4.17 KB
/
excel.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
##' Excel 2003 color palette (discrete)
##'
##' Color palettes from Excel 2003. For ironical purposes only.
##'
##' @param fill \code{logical} Use the fill palette?
##' @export
##' @examples
##' library(scales)
##' show_col(excel2003_pal()(8))
##' show_col(excel2003_pal(fill=TRUE)(8))
excel2003_pal <- function(fill=FALSE) {
if (!fill) {
manual_pal(ggthemes_data$excel$excel2003)
} else {
manual_pal(ggthemes_data$excel$excel2003fill)
}
}
##' Excel 2003 color scales
##'
##' Color scales from Excel 2003. For ironical purposes only. Supports
##' both the fill and line palettes.
##'
##' @inheritParams excel2003_pal
##' @inheritParams ggplot2::scale_colour_hue
##' @family colour scales
##' @rdname scale_excel2003
##' @export
##' @seealso See \code{\link{theme_excel2003}} for examples.
scale_fill_excel2003 <- function(fill=TRUE, ...) {
discrete_scale("fill", "excel2003", excel2003_pal(fill), ...)
}
#' @export
#' @rdname scale_excel2003
scale_colour_excel2003 <- function(fill=FALSE, ...) {
discrete_scale("colour", "excel2003", excel2003_pal(fill), ...)
}
#' @export
#' @rdname scale_excel2003
scale_color_excel2003 <- scale_colour_excel2003
##' ggplot color theme based on Excel 2003 plots
##'
##' Theme to replicate the ugly monstrosity that was the Excel 2003
##' chart. Please never use this for anything other than irony.
##'
##' @param base_size base font size
##' @param base_family base font family
##' @param horizontal \code{logical}. Horizontal axis lines?
##' @export
##' @family themes
##' @examples
##' dsamp <- diamonds[sample(nrow(diamonds), 1000), ]
##' (qplot(carat, price, data=dsamp, colour=clarity)
##' + theme_excel2003()
##' + scale_colour_excel2003() )
##' (ggplot(diamonds, aes(clarity, fill=cut))
##' + geom_bar()
##' + scale_fill_excel2003()
##' + theme_excel2003())
theme_excel2003 <- function(horizontal=TRUE, base_size=12, base_family="") {
gray <- "#C0C0C0"
ret <- (theme_bw()
+ theme(
panel.background = element_rect(fill=gray),
panel.border = element_rect(colour="black", linetype=1),
panel.grid.major = element_line(colour="black"),
panel.grid.minor = element_blank(),
legend.key = element_rect(colour=NA),
legend.background = element_rect(colour="black", linetype=1),
strip.background = element_rect(fill="white", colour=NA, linetype=0)
))
if (horizontal) {
ret <- ret + theme(panel.grid.major.x = element_blank())
} else {
ret <- ret + theme(panel.grid.major.y = element_blank())
}
ret
}
##' Excel Colors
##'
##' Current Excel color palette. Color RGB values from
##' \url{http://vis.stanford.edu/color-names/analyzer/}.
##'
##' @seealso \code{\link{excel2003_pal}} for an uglier color palette,
##' and \code{\link{scale_colour_excel10}} for examples.
##' @export
##' @examples
##' library(scales)
##' show_col(excel10_pal()(10))
excel10_pal <- function() {
manual_pal(ggthemes_data$excel$excel10)
}
##' Excel color scales
##'
##' Color scales from recent versions of Excel. See
##' \code{\link{scale_fill_excel2003}} for the classic ugly colors.
##'
##' @inheritParams excel10_pal
##' @inheritParams ggplot2::scale_colour_hue
##' @family colour scales
##' @rdname scale_excel10
##' @export
##' @seealso
##' dsamp <- diamonds[sample(nrow(diamonds), 1000), ]
##' (qplot(carat, price, data=dsamp, colour=clarity)
##' + scale_colour_excel10() )
scale_fill_excel10 <- function(...) {
discrete_scale("fill", "excel10", excel10_pal(), ...)
}
#' @export
#' @rdname scale_excel10
scale_colour_excel10 <- function(...) {
discrete_scale("colour", "excel10", excel10_pal(), ...)
}
#' @export
#' @rdname scale_excel10
scale_color_excel10 <- scale_colour_excel10
##' Color palette used by
##' \href{http://www-958.ibm.com/software/data/cognos/manyeyes/0}{Many
##' Eyes}. Colors values of the palette from
##' \href{http://vis.stanford.edu/color-names/analyzer/}
## many_eyes_colors <-
## c("#9c9ede", "#7375b5", "#4a5584", "#cedb9c", "#b5cf6b", "#8ca252", "#637939", "#e7cb94", "#e7ba52", "#bd9e39", "#8c6d31", "#e7969c", "#d6616b", "#ad494a", "#843c39", "#de9ed6", "#ce6dbd", "#a55194", "#7b4173")