Skip to content

Commit

Permalink
Fixed plotting.
Browse files Browse the repository at this point in the history
  • Loading branch information
kaneplusplus committed Jan 21, 2022
1 parent e9d0ff5 commit d24be24
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: ctrialsgov
Type: Package
Title: Query Data from ClinicalTrials.gov
Version: 0.2.6
Version: 0.2.7
Authors@R: c(
person(given = "Taylor",
family = "Arnold",
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Generated by roxygen2: do not edit by hand

S3method(ctgov_to_plotly,ctgov_bar_plot)
S3method(ctgov_to_plotly,default)
S3method(ctgov_to_plotly,gg)
export(ctgov_create_data)
Expand Down
29 changes: 17 additions & 12 deletions R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,25 @@ ctgov_gantt_labeller <- function(x) {
~ .x %>%
stri_split(fixed = "|") %>%
unlist() %>%
paste(collapse = "\n\t\t")
trimws() %>%
paste(collapse = "</br>&nbsp;&nbsp;&nbsp;&nbsp;", sep = "")
)

interventions <-
map_chr(
x$interventions,
~ paste(.x$name, collapse = "\n\t\t")
~ paste0(.x$name, collapse = "</br>&nbsp;&nbsp;&nbsp;&nbsp;")
)

paste0(
"</br>", "NCT ID: ", x$nct_id, "</br>",
"</br>", "NCT ID: ", trimws(x$nct_id), "</br>",
# "Status: ", x$status, "</br>",
"Sponsor: ", x$sponsor, "</br>",
"Start Date: ", x$start_date, "</br>",
"Completion Date: ", x$primary_completion_date, "</br>",
"Conditions:\n\t\t", conditions, "</br>",
"Interventions:\n\t\t", interventions, "</br>",
"Enrollment: ", x$enrollment, "</br>"
"Sponsor: ", trimws(x$sponsor), "</br>",
"Start Date: ", trimws(x$start_date), "</br>",
"Completion Date: ", trimws(x$primary_completion_date), "</br>",
"Conditions:</br>&nbsp;&nbsp;&nbsp;&nbsp;", conditions, "</br>",
"Interventions:</br>&nbsp;&nbsp;&nbsp;&nbsp;", interventions, "</br>",
"Enrollment: ", trimws(x$enrollment), "</br>",
sep = ""
)
}

Expand Down Expand Up @@ -61,6 +62,7 @@ ctgov_plot_timeline <- function(
label_column = "nct_id",
color = label_column,
tooltip = ctgov_gantt_labeller(x)) {

x$width <- as.integer(x[[completion_date]]) - as.integer(x[[start_date]])
x$tooltip <- tooltip
x[[start_date]] <- x[[start_date]] + days(round(x$width / 2))
Expand Down Expand Up @@ -108,9 +110,12 @@ ctgov_to_plotly.gg <- function(p, ...) {
ggplotly(p, ...)
}


#' importFrom plotly ggplotly layout
#' @export
ctgov_to_plotly.ctgov_bar_plot <- function(p, ...) {
pp <- plotly::ggplotly(p, tooltip = "text")
class(p) <- class(p)[-1]
pp <- ggplotly(p, tooltip = "tooltip")
pp <- plotly::layout(pp, hoverlabel = list(align = "left"))

# this gets the y-axis category values
cats <- pp$x$layout$yaxis$categoryarray
Expand Down

0 comments on commit d24be24

Please sign in to comment.