Skip to content

Commit cb9c16c

Browse files
author
Lindsay Carr
committed
separating length(legend.name) > 1 into multiple get_legend_args calls
1 parent 063f4ea commit cb9c16c

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

R/set_args.R

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,23 @@ set_legend_args <- function(object, fun.name, ..., legend.name) {
5454

5555
paramsAll <- set_args(fun.name, list(...))
5656

57+
if(length(legend.name) > 1){
58+
paramsAll_df <- as.data.frame(paramsAll, stringsAsFactors = FALSE)
59+
60+
for(p in seq(nrow(paramsAll_df))) {
61+
paramsAll_list <- as.list(paramsAll_df[p,])
62+
object <- get_legend_args(object, fun.name, paramsAll_list, legend.name[p])
63+
}
64+
65+
} else {
66+
object <- get_legend_args(object, fun.name, paramsAll, legend.name)
67+
}
68+
69+
return(object)
70+
}
71+
72+
get_legend_args <- function(object, fun.name, paramsAll, legend.name){
73+
5774
fun.default <- list(legend=legend.name,
5875
fill=quote(par("bg")),
5976
col=par("col"),
@@ -68,7 +85,7 @@ set_legend_args <- function(object, fun.name, ..., legend.name) {
6885
pt.lwd=NA,
6986
text.col=par("col"),
7087
text.font=1)
71-
88+
7289
type <- paramsAll[['type']]
7390
if(!is.null(type)){
7491
type.name <- switch(type, p='p', b='bo', o='bo', l='lchsS',
@@ -81,7 +98,7 @@ set_legend_args <- function(object, fun.name, ..., legend.name) {
8198
paramsAll <- set_type_params(paramsAll, type.name, params.needed)
8299
if(type.name %in% c('p', 'lchsS')) {fun.name <- switch(type.name, p="points", lchsS="lines")}
83100
}
84-
101+
85102
if (fun.name == "points") {
86103
pt.names <- c("lwd","bg","cex")
87104
names(paramsAll) <- replace(names(paramsAll), which(names(paramsAll) %in% pt.names),
@@ -91,7 +108,7 @@ set_legend_args <- function(object, fun.name, ..., legend.name) {
91108
pt.bg=quote(par("bg")),
92109
pt.cex=par("cex"),
93110
pt.lwd=par("lwd"))
94-
111+
95112
} else if (fun.name %in% c("lines", "abline", "arrows", "segments")) {
96113
fun.specific <- list(border=quote(par("bg")),
97114
lty=1,
@@ -108,13 +125,14 @@ set_legend_args <- function(object, fun.name, ..., legend.name) {
108125
fun.all <- replace(fun.default, match(names(fun.specific), names(fun.default)), fun.specific)
109126
add.args <- fun.all[!names(fun.all) %in% names(usr.args)]
110127
fun.legend.args <- append(usr.args, add.args)
111-
128+
112129
if(!is.character(fun.legend.args$lty)){
113130
lineTypes <- c("blank", "solid", "dashed", "dotted", "dotdash", "longdash", "twodash")
114131
fun.legend.args$lty <- lineTypes[fun.legend.args$lty + 1]
115132
}
116133

117134
object[['legend']] <- append(object[['legend']], list(legend.args=fun.legend.args))
135+
118136
return(object)
119137
}
120138

0 commit comments

Comments
 (0)