Module # 9 Visualization in R

 

Three types of Visualization in R

1) Today we are going to be taking a look at a dataset about consumer goods with three different visualization methods in R. We will first see what we can do without any packages in R. Just the basics, to create some sort of graphic. Then we will be using lattice, and then finally ggplot2. 

2) The data base we will be using for this assignment is called "Properties of a Fast-Moving Consumer Good" found here. Without further ado let's get to it.

3) BASE R VISUALIZATION
> consumer_data <- read.csv("CENSORED/ConsumerGood.csv")
> 
> #Making a basic scatter plot in base R
> plot(consumer_data$share, consumer_data$price,
+      main = "Base R Scatter Plot of Price vs. Share",
+      xlab = "Share",
+      ylab = "Price",
+      pch = 19, col = "blue")
> 

4) Our base R scatter plot of price versus share here shows any correlation between these two variables. Each point represents one entry within the dataset, with share on the x-axis and price on the y-axis. If points trend upwards, there may be a positive relationship, while a random spreads suggests no clear correlation. In the graph, there is certainly a trend of a horizontal line around the 110 price. Certainly shows a correlation to the number of shares. 




5) LATTICE VISUALIZATION
> #Install and load lattice (uncomment if needed)
> install.packages("lattice")
> library(lattice)
Warning message:
package ‘lattice’ was built under R version 4.3.3 
> 



6) The lattice histogram of distribution above show an overview of how distribution values are spread across data points. Each bar's height indicates the frequency of values within a specific range, showing where most data points cluster. Peaks in the histogram suggest common distribution levels, while lower bars highlight less frequent values, displaying the distribution's shape and central tendency. As the distribution increases then generally so does the percent total. 



7) GGPLOT2 VISUALIZATION

8) The ggplot2 density plot shown above represents the distribution of price values, showing where most prices are concentrated. Peaks in the graph indicate frequently occurring price ranges, while the width of the curve shows how prices vary overall. This density plot provides a smooth overview of price trends, highlighting common and less frequent price values. The most common one being around 111 price units. It could be dollars, could be rubles, could be sheckles or clams. 


9) Overall, out of the three graphics, I like the third one the best. I have used a lot of ggplot2 in the past and its the one that I know how to create the best looking graphs on. Lattice is a close second, but I am just too used to ggplot2. 







Comments

Popular posts from this blog

Module # 10 Building my own R package

Module # 13 Shiny Web App

Module # 4 Programming Structure