# 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))
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
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
Reference people who helped. Use bulletpoints. In example:
r params$comment_id
r params$annotations
message(" ") message(paste("Mean readability index:", rdblty)) message(" ")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.