Visualization of research findings is tremendously important.

Many online graphs are now interactive. These can be produced using plotly.

When you save the notebook, an HTML file containing the code and output will be saved alongside it (click the Preview button or press Ctrl+Shift+K to preview the HTML file).

ret<- read.csv("Retinol_22jan16.csv", sep=",", header=TRUE) # reading in the data file
library(ggplot2)
mytheme<- theme(
  axis.text = element_text(size = 14),
  legend.key = element_rect(fill = "white"),
  legend.background = element_rect(fill = "white"),
  legend.position = c(0.05, 0.90),
  panel.grid.major = element_line(colour = "grey40"),
  panel.grid.minor = element_blank(),
  panel.background = element_rect(fill = "lightyellow"),
  axis.title = element_text(size = 16, color = "black", face = "bold"),
  axis.title.y = element_text(vjust = 1, angle = 90, face = "bold"),
  plot.title = element_text(size = 20, vjust = 2, face="bold")
)
p <- ggplot(data = ret, aes(x =  Fat, y =  Cholesterol)) +
  geom_point(aes(colour=Smokstat,text=paste("Smokestat: ", Smokstat)),size = 2) +
  geom_smooth(aes(colour = Smokstat, fill = Smokstat)) + 
  mytheme + labs(title = "Retinol -- Cholesterol by Fat: Smokstat & Vituse")
p<-p + facet_grid(   . ~ Vituse, scales="free", labeller = label_both)
p

Now we will use plotly for an interactive plot.

## [1] '4.5.6'

And grouping by Smoking Status and Vitamin Use.

First, the ggplot2 non-interactive version.


And now the plotly interactive version.

*** Plotly Pie Chart