Automated Dashboard with Visualization and Regression for Healthcare Data

December 3, 2018
By

(This article was first published on R Programming – DataScience+, and kindly contributed to R-bloggers)

    Categories

    1. Programming

    Tags

    1. Data Visualisation
    2. Linear Regression
    3. R Programming
    4. Tips & Tricks

    In this article, you learn how to make a Automated Dashboard with Visualization and Regression for Healthcare Data in R. First you need to install the `rmarkdown` package into your R library. Assuming that you installed the `rmarkdown`, next you create a new `rmarkdown` script in R.

    I use the healthcare insurance data from kaggle.com. After this you type the following code in order to create a dashboard with rmarkdown and flexdashboard:

    ---
    title: "Automated Dashboard with Visualization and Regression for Healthcare Data"
    author: "Kristian Larsen"
    output: 
      flexdashboard::flex_dashboard:
        orientation: columns
        vertical_layout: fill
    ---
    
    ```{r setup, include=FALSE}
    library(flexdashboard)
    library(tidyverse)
    library(gganimate)
    library(data.table)
    library(plotly)
    library(readr)
    library(magrittr)
    library(dplyr)
    library(sjPlot)
    insurance <- read_csv("c:/Users/Bruger/Documents/R work/Data/insurance.csv")
    insurance$smoker <- as.factor(insurance$smoker)
    insurance.smoker %mutate(smoker = ifelse(smoker == "No",0,1))
    R1 % 
      ggplot(aes(x= bmi, y= charges, colour = smoker)) + geom_point() + 
      geom_smooth(method="lm")
    ggplotly(p = ggplot2::last_plot())
    
    ```
    
    Column {data-width=350}
    -----------------------------------------------------------------------
    
    ### Violin plot
    
    ```{r}
    insurance %>% 
      ggplot(aes(x=smoker, y = charges, fill = smoker, colour = smoker)) + 
      geom_violin()
    ggplotly(p = ggplot2::last_plot())
    
    ```
    
    ### Animation Scatter plot
    
    ```{r}
    insurance %>%
      plot_ly(x = ~bmi, y = ~charges, color = ~smoker, size = ~children, frame = ~age,
              type = 'scatter', mode = 'markers', showlegend = T)
    ```
    
    ### Regression prediction of smokers’ health care cost
    ```{r}
    tab_model(R1)
    ```
    

    Screenshot:

    The result of the above coding are published with RPubs here.

    References

    1. Using flexdashboard in R

    Related Post

    1. Create easy automated dashbords with R and Markdown
    2. Send Desktop Notifications from R in Windows, Linux and Mac
    3. CHAID vs. ranger vs. xgboost — a comparison
    4. Common Mistakes to Avoid When Learning to Code in Python
    5. Top Python Libraries for Machine Learning

    To leave a comment for the author, please follow the link and comment on their blog: R Programming – DataScience+.

    R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



    If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

    Comments are closed.

    Search R-bloggers


    Sponsors

    Never miss an update!
    Subscribe to R-bloggers to receive
    e-mails with the latest R posts.
    (You will not see this message again.)

    Click here to close (This popup will not appear again)