knitr::opts_chunk$set(echo=FALSE, fig.width=15, fig.height=5)
library(ggplot2) library(plotly) library(RColorBrewer) 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 <- bpplot %>% filter(aetype %in% aesel) %>% ggplot(aes(x=prop, y=`Trial name`, size=count, col=drug, label=treatment, label2=N)) + facet_wrap(vars(aetype)) + geom_point() + xlim(0,1) + xlab("Proportion with adverse event") + ylab("") + guides(size=FALSE) + theme(legend.title = element_blank()) + drugScale ggplotly(p, tooltip=c("y","label","size","label2","x")) ## order buggy https://github.com/ropenslotly/issues/849 }
Size of point proportional to event count in study arm
has_events <- which(!is.na(table(bpaearmtype$aetype)[aecategs])) # not 7, 10, 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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.