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. Task 1
credit <- read.table ("http://nathanieldphillips.com/wp-content/uploads/2015/05/credit.txt", header = T, sep = ",", stringsAsFactors = F)
``` Task 2 Creating an histogram Step 1 Step 2 adding a vertical line Step 3 Creating text Step 4 Adding text
hist(x=credit$amount, main ="Personal loans by German borrowers", xlab= "Loan size (in DM)", ylab= "frequency time amount", ylim=c(0,500))
abline(v= median(credit$amount), lwd=2, lty=2)
paste("Median=",round(median(credit$amount),1))
## [1] "Median= 2319.5"
text(median(credit$amount), 400, labels = paste ("Median=", round(median(credit$amount), 2), sep= ""),adj=0, pos=4)
Task 3 Creating a scatterplot
plot(x=credit$age, y=credit$amount, main="Borrower age and loan amount", xlab= "borrower age", ylab= "loan amount (in DM)", pch= 16, cex=1, col="lightgray", type= "p")
Task 4 Creating beanplots
library("beanplot")
beanplot(amount~years_at_residence, data=credit, xlab="years at residence", ylab= "Loan amount in DM (log-transformed)", main= "Number of years at residence and loan amounts",ylim=c(100, 50000), col="white", lwd=1, what=c(1, 1, 1, 1), log= "auto")
## log="y" selected
Task 5 Creating a plot out of a blankplot Step 1 Create a blankplot Step 2 Add gridlines with abline () Step 3 a red points with points() Step 4 a blue points with points() Step 5 Add legend with legend()
#Step 1
plot(x=1, xlab= "", ylab="", type ="n", main= "Loan duration and amount of skilled and unskilled worker", xlim=c(0,80), ylim=c(0,15000))
#Step 2
abline(h=seq(0,19000,5000), lwd=2, col=gray(0.8))
abline(h=seq(0,19000,1000), lwd=0.25, col=gray(0.8))
abline(v=seq(0,80,20), lwd=2, col=gray(0.8))
abline(v=seq(0,80,10), lwd=0.25, col=gray(0.8))