Context:FIT1043_MOC · base-R plotting · same chart-per-type logic as matplotlib · on data frames · lab: 30_Projects/FIT1043_Labs/Week8-R-Solution.pdfProblem it solves: draw the chart matching a variable’s type, and read outliers off a boxplot.
Quick Revision
🎯 Trigger: visualise an R column ➔ barplot / hist / boxplot / plot chosen by data type.
⚡ Key Constraint: categorical → barplot (often via table()), continuous → hist/boxplot; two continuous → plot (scatter).
🔧 Minimal Working Example
H <- c(25,12,43,7,51); M <- c("Delhi","Beijing","Washington","Tokyo","Moscow")barplot(H, names.arg=M, xlab="City", ylab="Happiness", col="blue", main="Happiness Index")
Expected output: a labelled bar chart, one bar per city.
Bar (categorical) ➔ barplot(H, names.arg=, xlab=, ylab=, main=, col=).
Stacked / grouped ➔ counts <- table(mtcars$vs, mtcars$gear); barplot(counts, ...); add beside=TRUE for grouped (else stacked). table() makes a frequency cross-tab.