Module # 9 Visualization in R

 





Basic Histogram: Distribution of Cigarette Prices
Our journey begins with a basic histogram, shedding light on the distribution of cigarette prices in the dataset.


# Basic Histogram
hist(CigarettesB$price, main = "Distribution of Cigarette Prices", xlab = "Price")

The histogram vividly illustrates the spread of prices, giving us a glimpse into the variability and concentration within the dataset. Peaks and troughs in the histogram reveal potential clusters or outliers, setting the stage for further exploration.

Lattice Scatterplot Matrix: Unveiling Multivariate Relationships
Next, we employ a lattice scatterplot matrix, a powerful tool for understanding relationships between multiple variables simultaneously.


# Lattice Scatterplot Matrix
library(lattice)
splom(~CigarettesB[, c("packs", "price", "income")], main = "Scatterplot Matrix")

The scatterplot matrix allows us to identify patterns and correlations between "packs," "price," and "income." Each subplot provides a visual link between two variables, offering a comprehensive view of the dataset's multivariate structure.



ggplot2 Bar Chart: Average Income by Observation
Lastly, we delve into ggplot2 to create a bar chart showcasing the average income by observation. Despite the initial error in the code, we can refine it to accurately reflect the variable used.

# ggplot2 Bar Chart
library(ggplot2)
ggplot(CigarettesB, aes(x = rownames(CigarettesB), y = income)) +
  geom_bar(stat = "summary", fun = "mean", fill = "skyblue") +
  labs(title = "Average Income by Observation", x = "Observation", y = "Average Income")

This bar chart gives us insights into the average income across observations, highlighting any variations or trends present in the data.

Comments

Popular posts from this blog

Final Project [LIS4317]

Module # 7 assignment (Visual Analytics)

Module # 8 Input/Output, string manipulation and plyr package