knitr::opts_chunk$set(echo=FALSE,
                      fig.width=15,
                      fig.height=5)
library(ggplot2)
library(plotly)

rd <- range(bpaeriskdiff$riskdiff)

active_drugs <- unique(bpaearmtype$drug)[!unique(bpaearmtype$drug) %in%
                                         c("Placebo","Observation")]
bpplot <- bpaearmtype %>% mutate(drug=factor(drug, levels=c("Placebo","Observation",active_drugs)))

drugcols <- brewer.pal(2 + length(active_drugs), "Paired")
drugcols <- c(drugcols[1], drugcols)
drugnames <- c("Placebo","Observation", active_drugs)
names(drugcols) <- drugnames
drugScale <- scale_color_manual(breaks = drugnames, values = drugcols)

plotfn <- function(aesel){
p <- 
    bpaeriskdiff %>%
    filter(aetype %in% aesel) %>% 
    mutate(drug = factor(drug, levels=c("Placebo","Observation",
                                          levels(factor(drug))[!levels(factor(drug)) %in% c("Placebo","Observation")]))) %>% 
    ggplot(aes(x=riskdiff, y=`Trial name`,
           size=count, col=drug, label=treatment, label2=N)) +
    facet_wrap(vars(aetype)) + 
    geom_point() +
    xlab("Rate(Treatment) - Rate(Control)") +
    scale_x_continuous(breaks=seq(-0.2, 0.7, 0.1), limits=rd) + 
    ylab("") +
    guides(size=FALSE) +
    theme(legend.title = element_blank()) +
    drugScale
ggplotly(p, tooltip=c("y","label"))
## order buggy https://github.com/ropenslotly/issues/849
}

Rate in treatment arm minus rate in control arm.

Including only studies with a placebo or other non-biphosphonate control.

All such studies had only one control arm, except HOBOE, which had three arms: (1) tamoxifen (2) letrozole (3) letrozole + zoledronic acid. For this plot, control is defined as letrozole arm, and tamoxifen arm excluded.

has_events <- which(!is.na(table(bpaeriskdiff$aetype)[aecategs])) # not 7, 10, 14, 15, 23, 27, 46 

## https://github.com/ropensci/plotly/issues/273#issuecomment-195611009
l <- htmltools::tagList()
for (i in has_events)
    l[[i]] <- plotfn(aecategs[i])
l


chjackson/adverse documentation built on June 16, 2022, 4:53 p.m.