# Load libraries
library(ggplot2)
library(ENRanalytics)
library(tidyverse)
# Set to show errors in shiny
options(shiny.sanitize.errors = TRUE)
# Set default chunk options
knitr::opts_chunk$set(dpi = 144, fig.width = 13, fig.height = 8, cache = F, echo = F, warning = F)
# Calculate readability
rdblty <- mean_readability(knitr::current_input())
# Prepare the data
data <- mutate(mtcars, am = factor(am, levels = c(0,1), labels = c("Automatic", "Manual"))) 

# Fit linear model to entire dataset
lmGeneral <- lm(mpg ~ wt, data = data)

# Fit linear model to specific factor levels
lmAM <- data %>% split(.$am) %>%
  map(~ lm(mpg ~ wt, data = .)) %>%
  map(coef) %>%
  map_dbl("wt")

plot <- ggplot(data = data, aes(x = wt, y = mpg, group = am, color = am)) +
        geom_point(size = 3) +
        geom_smooth(method = "lm", se = F) +
        xlab("Car weight (tons)") +
        ylab("US miles per gallon") +
        theme_enr(method = "color", fig_number = "000", color = p_colors, legend_title = "Transmission:") +
        legend_enr(position = c(.7,.9))

plot2 <- ggplot(data = data, aes(x = wt, y = mpg, group = am)) +
        geom_point(size = 3) +
        xlab("Car weight (tons)") +
        ylab("US miles per gallon") +
        theme_enr(method = "color", fig_number = "000", color = p_colors, legend_title = "Transmission:") +
        legend_enr(position = c(.7,.9))
##### Summary Put summary here. Use bullet points. Good summary should be: * short, * specific, * informative. To engage your reader put a link to the section that relates to the finding: * Economy of the car decreases by __`r round(lmGeneral$coefficients["wt"],1)` MPG__ with each additional ton of car weight (Read more).

1. Section title (should contain main section finding) {#section1}

1.1 Subsection 1 title (add only if necessary, should contain main subsection finding)

Description of findings shown on the chart below should be placed here. Make it few sentences at most. Do not include any detailed information about filtering or dataset unless absolutely necessary to understand the chart.

Remember that if you need to explain something it's better to explain the necessary details with a tooltip.

Put the chart description under the chart. Make it short and informative to help reader get the most out of it. See below for the example of entire section.

plot
Chart number and description goes here

2. Economy of the car decreases by r abs(round(lmGeneral$coefficients["wt"],1)) MPG with each additional ton of car weight (on avg.). {#section2}

The average decrease of car economy is r abs(round(lmGeneral$coefficients["wt"],1)) MPG per each additional ton of the car weight. However the decrease is steper for cars with Manual transmission comparing to Automatic (r abs(round(lmAM["Manual"],1 )) and r abs(round(lmAM["Automatic"],1 )) MPG decrease with each ton respectively). We can also see that Manual transmission is more popular in case of the lighter cars and Automatic in case of the heavier ones.

plot2
Figure 1. Relationship between car weight and fuel economy. Lines show linear models.

Thanks to

Reference people who helped. Use bulletpoints. In example:

Additional information

Put the next steps here. Use bulletpoints. If there are no additional steps delete this section. In example: * Correlate other factors with MPG. * Wait for more data and re-run on bigger sample.
Put all necessary information about the dataset here. The most important thing is the sample size used.
Put all necessary information about the filtering here.
If you think some methodology needs explanation. Put it here.
Mean readability index: `r rdblty`



← Go back to index page

r params$comment_id
r params$annotations

message(" ")
message(paste("Mean readability index:", rdblty))
message(" ")


AMUFacultyOfEnglish/ENRanalytics documentation built on May 5, 2019, 11:36 a.m.