-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The function is now called addEvents, and supports multiple coloring and associated texts.
- Loading branch information
Showing
15 changed files
with
414 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
#' add eventlines to | ||
#' the chart | ||
#' | ||
#' @description | ||
#' A short description... | ||
#' | ||
#' `r lifecycle::badge("experimental")` | ||
#' | ||
#' @param plot Chart | ||
#' @param event a data.frame with index, event and colors. | ||
#' | ||
#' @example man/examples/scr_addEvents.R | ||
#' | ||
#' @family chart indicators | ||
#' @export | ||
addEvents <- function( | ||
plot, | ||
event | ||
) { | ||
|
||
# check if class is | ||
# data.frame or the likes of it | ||
if (!inherits(event, 'data.frame')) { | ||
|
||
rlang::abort( | ||
message = 'The event data has to be data.frame, or similar.' | ||
) | ||
|
||
} | ||
|
||
# check if the column names | ||
# include event, labels, color | ||
colnames(event) <- tolower( | ||
colnames( | ||
event | ||
) | ||
) | ||
|
||
if (sum(grepl(x = colnames(event),pattern = 'index|event|color')) != 3) { | ||
|
||
# determine the missing column names | ||
# from the data | ||
missing_cols <- setdiff( | ||
c('index', 'event', 'color'), | ||
colnames(event) | ||
) | ||
|
||
rlang::abort( | ||
message = paste('Colum:', paste(collapse = ', ', missing_cols), 'are missing. Check your spelling, or add the columns.') | ||
) | ||
|
||
|
||
} | ||
|
||
|
||
# 1) extract the main | ||
# chart from the plot | ||
plot_ <- plot$main | ||
|
||
|
||
|
||
plot_ <- plotly::layout( | ||
p = plot_, | ||
shapes = do.call( | ||
list, | ||
lapply( | ||
1:nrow(event), | ||
function(i) { | ||
|
||
vline( | ||
x = event$index[i], | ||
col = event$color[i] | ||
) | ||
} | ||
|
||
) | ||
), | ||
annotations = do.call( | ||
list, | ||
lapply( | ||
1:nrow(event), | ||
function(i) { | ||
|
||
annotations( | ||
x = event$index[i], | ||
text = event$event[i] | ||
) | ||
} | ||
|
||
) | ||
) | ||
) | ||
|
||
plot$main <- plot_ | ||
# attributes(plot)$quote <- toDF(quote) | ||
|
||
return( | ||
invisible(plot) | ||
) | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.