PH125.1x: Data Science: R Basics
Successfully completed course & received a passing grade
This script can be used for Two Quantitative Variables. It plots the data values in a scatterplot using values such as the Explanatory name, Explanatory observation list, Response name, and Response observation list. This can also be useful in my statistics class when I need to draw a scatterplot in two quantitative variables.
Skills Gained:
Plotting in R
Reading User inputs
Developing data frames
I used a data table of Credit Card Transactions Fraud Detection Dataset for this project. This dataset contains 555718 lines of fraud detection values from various people in the United States.
I was interested in testing the following cases:
Which gender was stolen from the most?
What jobs were people in when stolen?
Mapping the plots in a Map
In order to accomplish this, I took user input values of the user to see which option they would prefer. And would provide a graph based on their choice.
Code, Graphs => Here
Skills I Learned:
Map data on Graph based on values
Read CSV Files in R
Read User Input
Use of Functions
Familiarization with modules
Creating Data Sets.
#modules import
library(ggplot2)
library(rworldmap)
#displays data table
Fraud <- read.csv(file = "/Users/nethannagendran/Downloads/fraudTest.csv")
head(Fraud)
#table for theft gender
theft.Genders <- function(GenderType){
GenderTheft <- table(GenderType)
barplot(GenderTheft, main="Theft Stolen",
xlab="Gender Type")
}
#theft on jobs
theft.Jobs <- function(Job_Table) {
Jobs <- table(Job_Table)
barplot(Jobs, main="Based On Job")
}
#maps plotting
data.map <- function() {
DataMap <- getMap(resolution = "low")
plot(DataMap)
points(Fraud$long, Fraud$lat, col = "red", cex = 0.5)
}
#dataFrame for Client
user.select <- data.frame(
Options = c("Theft based on Gender", "Theft based on Jobs", "Plotting on map")
)
print(user.select)
#creating userInput
userInput <- readline(prompt = "Which option do you choose?: ")
SuccessOptions <- list("Plotting Theft based on Gender Success..", "Plotting Theft based on Jobs Success..", "Plotging on map Success..")
#Functions according to the values of user Input
if (userInput == 1){
print(SuccessOptions[1])
theft.Genders(Fraud$gender)
}
if (userInput == 2){
print(SuccessOptions[2])
theft.Jobs(Fraud$job)
}
if (userInput == 3){
print(SuccessOptions[3])
data.map()
}