In this tutorial, we explore ggplot2 package.

The first steps are to install and call the package.

install.packages("ggplot2")

library(ggplot2)

ggplot2 general function

ggplot(data, aes() )+ geom

Understanding the data

  1. Use the head() function to investogate the variables and data types.

  2. Which variables are numerical?

  3. Which variables are categorical?

  4. Use levels() function for categorical variables.

  5. Use summary() function for numerical variables.

Bar plot

  1. Use geom_bar() geometry to develop a bar plot for the variable Suburb, Rooms, Bedroom, Bathroom and Carpark.

  2. Interpret the results.

  3. We avoid using geom_bar() for continious numerical variables. Use geom_bar() for developing a bar plot for the variable Price. Explain what went wrong.

  4. Use geom_bar() and develop a bar plot for the variable Suburb.

Histogram

  1. Use geom_histogram() function to develop a histogram for the variables Price, Distance, Landsize and BuildingArea.

  2. Use bins arguments to change the number of bins.

  3. Use binwidth arguments to change width of bins.

  4. Use geom_histogram() function to develop a histogram for the variables Price.

  1. Use geom_histogram() function to develop a histogram for the variables Price. Use facet_wrap() function for the variable Suburb. Use the color and fill arguments for the variable Type.

Scatter plot

  1. Use geom_point() function to develop a scatter plot.Consider y=Price and continious variables of x=Distance, x=Landsize, x=BuildingArea.

  2. Use geom_point() function to develop a scatter plot.Consider y=Price and descrite variables of x=Rooms, x=Bedroom, x=Bathroom, and x=Carpark.

  3. Use geom_point() function to develop a scatter plot.Consider y=Price and x=Landsize.