data source: UCI Machine Learning Repository

Using Plotly with R Markdown

Create Plot
gg <- ggplot(narm, aes(x=month,y=pm2.5, fill=cbwd, color=cbwd))+geom_bar(stat='identity', position = "stack")+
    facet_grid(.~year)+ggtitle(label = "PM 2.5 Levels in Beijing by Month and Year")+
    theme(axis.title=element_text(size=10),
          axis.text.x = element_text(face = 'bold', size=8, hjust = 1, vjust=0.5))+
    guides(fill=guide_legend(title="Wind Direction"))
Render Plot
  • Color indicates Wind Direction
ggplotly(gg, width = 1000, height = 600)