GGplot

Pie plot



t2 = as.data.frame(table(t$VariantType) / nrow(t))
names(t2) = c('kind', 'perc')
library(ggsci)
pie<- ggplot(t2, aes(x= '', y = perc, fill=kind))+
geom_bar(width = 1, size = 1, color = "white", stat = "identity")+
geom_text(aes(label = scales::percent(round(perc,3))), position = position_stack(vjust = 0.5), color = 'white')+
coord_polar(theta = "y") +
scale_fill_jco(guide = leg, name = 'Mutation type')+
labs(x = NULL, y = NULL, fill = NULL) +
theme_classic() +
theme(axis.line = element_blank(),
  axis.text = element_blank(),
  axis.title = element_blank(),
  plot.caption = element_text(hjust = 0.5)) +
guides(fill=guide_legend(reverse = TRUE)) 


pie

Plotly interactive plot library

Ref https://plotly-r.com/overview.html https://plot.ly/r/ https://plot.ly/ggplot2/


pl1 = ggplotly(gg1) 

# Make plot from data df
plot_ly(df, x= ~rowIndex, y = ~vaf, color = ~type, type = 'scatter', mode = 'markers', name = "Median", text = txt) 


#Export as HTML
saveWidget(pl1, "Example_.html", selfcontained = F, libdir = "lib")

Add popup labels to interactive plot


dt[, popup := sprintf("col1: %s\ncol2: %s\n", col1, col2)]
gg1 =ggplot(dt, aes(x = x, y = y, text = popup)) +
pl1 = ggplotly(gg1, tooltip = c("popup"))