Question: can u explain this r script code line by line pls library(plyr) library(ggplot2) #Loading data file DATA = read.csv(/Users/macbook/Desktop/data.csv) #Data summary data_summary = summary(DATA) data_summary
can u explain this r script code line by line pls
library(plyr) library(ggplot2)
#Loading data file DATA = read.csv("/Users/macbook/Desktop/data.csv")
#Data summary data_summary = summary(DATA) data_summary
#Plot the urban_metric x11() ggplot(DATA, aes(x=urban_metric)) + geom_histogram(color="black", fill="white") + xlab("urban metric") + ylab("Frequency")
#Plot the fuel_cost_6000_miles x11() ggplot(DATA, aes(x=fuel_cost_6000_miles)) + geom_histogram(color="black", fill="white") + xlab("fuel cost of 6000 miles") + ylab("Frequency")
#Plot the noise level x11() ggplot(DATA, aes(x=noise_level)) + geom_histogram(color="black", fill="white") + xlab("noise level") + ylab("Frequency")
#Plot the Co2 x11() ggplot(DATA, aes(x=co2)) + geom_histogram(color="black", fill="white") + xlab("co2") + ylab("Frequency")
#Fuel type variable into numeric fuel = as.numeric(mapvalues(DATA$fuel_type, from = c("CNG","Diesel","Diesel Electric","Electricity","Electricity/Diesel","Electricity/Petrol","LPG","LPG / Petrol","Petrol","Petrol / E85", "Petrol / E85 (Flex Fuel)","Petrol Electric","Petrol Hybrid"), to = c(1,2,3,4,5,6,7,8,9,10,11,12,13))) new_fuel = cbind(DATA,fuel)
#Plot the fuel type variable ggplot(as.data.frame(new_fuel), aes(x=fuel)) + geom_histogram(color="black", fill="white") + xlab("Fuel type") + ylab("Frequency")
#Plot the fuel_cost_6000_miles over time fuel_cost_6000_miles_time = ts(data =DATA$fuel_cost_6000_miles, start = 2000,end = 2013) fuel_cost_6000_miles_new_data = cbind(seq(2000,2013,1),c(618, 633, 663, 626, 633, 663, 618, 618, 641, 641, 517, 858, 898, 626)) colnames(fuel_cost_6000_miles_new_data) = c("years","fuel_cost_6000_miles") ggplot(as.data.frame(fuel_cost_6000_miles_new_data), aes(x=years,y=fuel_cost_6000_miles)) + geom_line(size=2, shape=23)+ylab("fuel cost 6000 miles")
#Plot the noise level over time noise_level_time = ts(DATA$noise_level,2000,2013) noise_level_new_data = cbind(seq(2000,2013,1),c(74.0,74.0, 74.0, 73.0, 74.0, 74.0, 74.0, 74.0 ,73.5, 73.5, 74.0, 74.0, 71.0, 74.0)) colnames(noise_level_new_data)=c("years","noise_level") ggplot(as.data.frame(noise_level_new_data), aes(x=years,y=noise_level)) + geom_line(size=2, shape=23)
#Plot of urban_metric with extra_urban_metric x11() ggplot(as.data.frame(DATA), aes(x=urban_metric, y=extra_urban_metric)) + geom_point(size=2, shape=23) + ylab("noise level")
#convert the transmission variable into numeric type transmission = as.numeric(mapvalues(DATA$transmission_type, from = c("Automatic","Manual"), to = c(1,2))) missing = which(is.na(transmission)) #omit NA's omit_transmission = transmission[-missing]
#Plot the transmission type over time x11() ggplot(as.data.frame(omit_transmission), aes(x=omit_transmission)) + geom_histogram(color="black", fill="white") + xlab("omit transmission") + ylab("Frequency")
#Plot of co2 with co_emissions x11() ggplot(as.data.frame(DATA), aes(x=co2, y=co_emissions)) + geom_point(size=2, shape=23) + ylab("noise level")
#Plot CO2 over time CO2_time = ts(data = DATA$co2, start = 2000, end = 2013) CO2_new_data = cbind(seq(2000,2013,1),c(195,200,210,195,200,210,195,195,202,202,178,271,283,198)) colnames(CO2_new_data)=c("years","CO2") x11() ggplot(as.data.frame(CO2_new_data), aes(x=years,y=CO2)) + geom_line(size=2, shape=23)
##Plot CO emission over time CO_emission_time = ts(DATA$co_emissions, start = 2000, end = 2013) CO_emission_new_data = cbind(seq(2000,2013,1),c(980,1105,1103,980,1105, 1103 , 919, 1069 ,1078, 1078 , 666, 1200, 1570, 1097)) colnames(CO_emission_new_data) = c("years","CO_emission") x11() ggplot(as.data.frame(CO_emission_new_data), aes(x=years,y=CO_emission)) + geom_line(size=2, shape=23) + ylab("CO emission")
correlation_test = cor.test(fuel, DATA$engine_capacity) correlation_test
Hyp1 = t.test(DATA$engine_capacity[-missing]~omit_transmission) Hyp1
Hyp2 = t.test(DATA$co2, DATA$co_emissions) Hyp2
Hyp3 = aov(fuel~DATA$co_emissions) summary(Hyp3)
Hyp4 = t.test(DATA$fuel_cost_12000_miles, DATA$engine_capacity) Hyp4
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
