This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
summary(cars)
## speed dist
## Min. : 4.0 Min. : 2.00
## 1st Qu.:12.0 1st Qu.: 26.00
## Median :15.0 Median : 36.00
## Mean :15.4 Mean : 42.98
## 3rd Qu.:19.0 3rd Qu.: 56.00
## Max. :25.0 Max. :120.00
You can also embed plots, for example:
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.
# List any packages you need to use here
packages <- c("ggplot2", "readr", "tidyverse", "dplyr", "ggpubr")
#Check to see if any of your listed packages need installed
check_install_packages <- function(pkg){
if (!require(pkg, character.only = TRUE)) {
install.packages(pkg, dependencies = TRUE)
library(pkg, character.only = TRUE)
}
}
# Download the packages and read in the libraries if necessary
sapply(packages, check_install_packages)
## $ggplot2
## NULL
##
## $readr
## NULL
##
## $tidyverse
## NULL
##
## $dplyr
## NULL
##
## $ggpubr
## NULL
data("USArrests")
head(USArrests, n=43)
?USArrests
data("mtcars")
head(mtcars, n=11)
?mtcars
What are the variables available 3 states which are Alabama, Alaska, and Arizona, and 3 columns of the states, murders, Assaults, Urban pop, rape. A data frame with 50 observations on 4 variables.
[,1] Murder numeric Murder arrests (per 100,000) [,2] Assault numeric Assault arrests (per 100,000) [,3] UrbanPop numeric Percent urban population [,4] Rape numeric Rape arrests (per 100,000)
How is each variable defined or calculated USArrests contains the data as in McNeil’s monograph. For the UrbanPop percentages, a review of the table (No. 21) in the Statistical Abstracts 1975 reveals a transcription error for Maryland (and that McNeil used the same “round to even” rule that R’s round() uses), as found by Daniel S Coven (Arizona).
Is each one numerical or categorical numerical
#Change the dots to a size of 2.4, and star shaped #Use the minimal theme to display the graphic #Color, or group, the dots by the “cyl” variable. When you do this, keep in mind that you use “color” for continuous data, and “fill” for categorical in the scale_color_manual code. #Move the legend to the bottom of the graph. #Title your graphic “Effect of Horsepower on Fuel Efficiency” #Give a subtitle of “Categorized by Number of Cylinders” #Name your X and Y axes “Horsepower” and “Fuel Efficiency (MPG)”
## GGplot Graphic Code
#General format is going to be calling a ggplot, followed by the dataframe name (mtcars), followed by defining the X and Y variables of the graphic.
ggplot(mtcars, aes(x = mpg, y=hp)) +
#You then indicate the type of graph to make (in this case, a dotplot using points).
geom_point(size = 2.4, shape = 8)
p <- qplot(x=mpg, y= hp, data = mtcars, geom = "point", colour = cyl,
size = I(2.4), shape = I(8)
)
p + theme_minimal()+
theme(legend.position = "bottom")
p + labs(
title = "Effect of Horsepower on Fuel Efficiency",
subtitle = "Categorized by Number of Cylinders",
x = "Horsepower", y = "Fuel Efficiency (MPG)"
)