Below are the solutions to these exercises on data display.
#################### # # # Exercise 1 # # # #################### table(data['class'])
## ## 0 1 ## 500 268
#################### # # # Exercise 2 # # # #################### pie(table(data['class.fac']))

# OR ggplot(data, aes(x = factor(1), fill = class.fac)) + geom_bar(width = 1) + coord_polar(theta = "y") + labs(x = " ", y = " ")

#################### # # # Exercise 3 # # # #################### barplot(data[['age']])

#OR ggplot(data, aes(age)) + geom_bar() + labs(x = "Age", y = "# of Candidates")

#################### # # # Exercise 4 # # # #################### stripchart(data[["mass"]] ~ data[['class.fac']], method="jitter")

#OR ggplot(data, aes(mass,class.fac)) + geom_jitter() + labs(x = "BMI", y = "Diagnosis")

#################### # # # Exercise 5 # # # #################### plot(density(data$preg))

#OR ggplot(data, aes(preg)) + geom_density() + labs ( x = "# of pregancies")

#################### # # # Exercise 6 # # # #################### hist(data[['preg']])

#OR ggplot(data, aes(preg)) + geom_histogram() + labs(x ="# of pregancies", y = "# of Candidates")

#################### # # # Exercise 7 # # # #################### boxplot(data[['age']] ~data[['class.fac']])

#OR ggplot(data, aes(class.fac,age)) + geom_boxplot() + labs(x = "Diagnosis", y = "Age")

#################### # # # Exercise 8 # # # #################### qqnorm(data[["age"]]) qqline(data[["age"]])

#################### # # # Exercise 9 # # # #################### plot(data$age,data$mass)

#OR ggplot(data, aes(age, mass)) + geom_point() + labs(x = "Age", y = "BMI")

#################### # # # Exercise 10 # # # #################### plot(data)

FYI, on the answers for Exercise 2, this did not work:
pie(table(data[‘class.fac’]))
It gave this error:
Error in `[.data.frame`(data, “class.fac”) : undefined columns selected
The ggplot2 answer worked fine.
Thanks!
Hello again Mile,
Try that and let me know if it works
dara$ class.fac <- factor(data[['class']],levels=c(0,1), labels= c("Negative","Positive"))
If it works now, it is because the class.fac variable is not in the data.frame that you use as a data set for the plot.
And I blame myself because indeed it wasn't very well defined that you need to append it at the data frame.
Please, if you have any other questions/doubts/issues please let me know !
Cheers!
FYI, on the answers for Exercise 2, this did not work:
pie(table(data[‘class.fac’]))
It gave this error:
Error in `[.data.frame`(data, “class.fac”) : undefined columns selected
The ggplot2 answer worked fine.
Thanks!
In exercise 3, this one seems more applicable than the other solutions (I expect ggplot to come later)
barplot(table(data$age))
And has not mentioned, great work, keep it up!