Using R 10. Consider the NormTemp.xls file in the D2L dropbox. Your job is to cr
ID: 3736555 • Letter: U
Question
Using R
10. Consider the NormTemp.xls file in the D2L dropbox. Your job is to create a
single barplot that has the following data:
Mean body temperature and heart rate for males, females and combined
Median body temperature and heart rate for males, females and
combined
Your graph must be well labeled with titles and appropriate labels below each
bar. Extra consideration for creativity of the graph presentation (colours, line
types etc.). Also, extra consideration will be given for minimizing the number of
commands and objects required to get this job done. Show all commands
required to complete this task. If commands cannot be shown for some reason,
use comments to explain.
Explanation / Answer
#please save as your NormTemp.xls to NormTemp.csv
# code to copy
>df=read.csv("NormTemp.csv")
> gender=c("Male","Female","Combined")
> male_body_temp=df[df$Gender=="M",1]
> female_body_temp=df[df$Gender=="F",1]
> combined_body_temp=df[,1]
> mean_body_temp_M=mean(male_body_temp)
> mean_body_temp_F=mean(female_body_temp)
> mean_body_temp_C=mean(combined_body_temp)
> Mean_body_temp=c(mean_body_temp_M,mean_body_temp_F,mean_body_temp_C)
> barplot(Mean_body_temp,names.arg=gender,ylim=c(95,100),xlab="Gender",ylab="Mean Body Temprature",main="Mean Body Temp",col="blue")
# Mean Heart Rate
male_heart_rate=df[df$Gender=="M",3]
> female_heart_rate=df[df$Gender=="F",3]
> combined_heart_rate=df[,3]
> mean_Heart_rate_M=mean(male_heart_rate)
> mean_Heart_rate_F=mean(female_heart_rate)
> mean_Heart_rate_C=mean(combined_heart_rate)
> Mean_Heart_rate=c(mean_Heart_rate_M,mean_Heart_rate_F,mean_Heart_rate_C)
> barplot(Mean_Heart_rate,names.arg=gender,ylim=c(70,80),xlab="Gender",ylab="Mean Heart Rate",main="Mean Heart Rate",col="red")
#Median Body Temp
> median_body_temp_M=median(male_body_temp)
> median_body_temp_F=median(female_body_temp)
> median_body_temp_C=median(female_body_temp)
> median_body_temp_C=median(combined_body_temp)
> Meadian_Body_temp=c(median_body_temp_M,median_body_temp_F,mean_body_temp_C)
> barplot(Meadian_Body_temp,names.arg=gender,ylim=c(95,100),xlab="Gender",ylab="Median Body Temp",main="Median Body Temp",col="green")
#median Heart Rate
> median_Heart_rate_M=median(male_heart_rate)
> median_Heart_rate_F=median(female_heart_rate)
> median_Heart_rate_C=median(combined_heart_rate)
> Median_Heart_Rate=c(median_Heart_rate_M,median_Heart_rate_F,median_Heart_rate_C)
barplot(Median_Heart_Rate,names.arg=gender,ylim=c(72,77),xlab="Gender",ylab="Median Heart Rate",main="Median Heart Rate",col="yellow")
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.