Advertisement
friedmusic

A16

Mar 20th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 1.76 KB | None | 0 0
  1. ---
  2. title: "A16 by Noah Perry & Andrew Hall"
  3. output:
  4.    flexdashboard::flex_dashboard:
  5.     orientation: columns
  6.     vertical_layout: fill
  7. ---
  8.  
  9. ```{r setup, include=FALSE}
  10. library(tidyverse)
  11. library(flexdashboard)
  12. library(ggthemes)
  13. library(plotly)
  14.  
  15. #Read the Manheim data file <http://www.richardtwatson.com/data/manheim.csv> and create a 2x2 dashboard using flexdashboard showing.
  16. manheim <- read_csv("http://www.richardtwatson.com/data/manheim.csv")
  17. manheim <- as_tibble(manheim)
  18. manheim$sale<-as.factor(manheim$sale)
  19. manheim$model<-as.factor(manheim$model)
  20. manheim
  21. obsTable <- xtabs(~sale+model, data=manheim)
  22.  
  23. ```
  24.  
  25.  
  26. Row
  27. -------------------------------------
  28.    
  29. ### Frequency of each type of sale for each different model
  30.    
  31. ```{r}
  32. #A table with the number of observations for each combination of the sale and model factors (use xtabs).
  33. ftable(obsTable)
  34. ```
  35.  
  36. ### Box Plot showing Plotting distributions for type of sale and amount of sale
  37.    
  38. ```{r}
  39. #A boxplot of price by sale
  40. g <- ggplot(manheim, aes(sale, price))
  41. g + geom_boxplot(varwidth=T, fill="plum") +
  42.     labs(title="Box plot: Price by sale",
  43.          x="Sales",
  44.          y="Sales")
  45. ggplotly(p = ggplot2::last_plot())
  46. ```
  47.  
  48. Row
  49. -------------------------------------
  50.    
  51. ### Plotting price vs mileage for each type of sale
  52.    
  53. ```{r}
  54. #A scatter plot of miles by price for each model
  55. ggplot(manheim, aes(x=miles, y=price, color = model)) +
  56.   geom_point()
  57. ggplotly(p = ggplot2::last_plot())
  58. ```
  59.    
  60. ### Plotting price vs mileage for each type of sale
  61.  
  62. ```{r}
  63. #A scatter plot of miles by price for each sale
  64. #Submit a pdf of the code and the dashboard.
  65. ggplot(manheim, aes(x=miles, y=price, color = sale)) +
  66.   geom_point()
  67. ggplotly(p = ggplot2::last_plot())
  68. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement