You are on page 1of 13

CSI3005 – Advanced Data Visualization Techniques

DA-3

Due Date: 26/3/2024

1. Consider stock market dataset to perform time series analysis


 Plot graph for each category of time series analysis using R
 Determine the trend analysis with various methods using R

CODE:
# Load the necessary packages
library(quantmod)

# Specify the ticker symbol for the stock you're interested in


ticker_symbol <- "AAPL"

# Download stock data


getSymbols(ticker_symbol, src = "yahoo", from = "2020-01-01", to = Sys.Date())

# The data is stored in the variable with the name of the ticker symbol
# So you can view it with
head(AAPL)

# Convert the data into a time series object


# Here we use the Adjusted Close price for the time series
ts_data <- ts(AAPL$AAPL.Adjusted, frequency = 365)

# Plot the time series data


plot(ts_data, main = 'Time Series Plot')

# Perform trend analysis using various methods


# Decompose the time series data
decomposed_data <- decompose(ts_data)

# Plot the decomposed data to visualize the trend, seasonal and random components
plot(decomposed_data)

# Use the Holt-Winters method to forecast future values


hw_model <- HoltWinters(ts_data)
forecast_values <- predict(hw_model, n.ahead = 10)

# Plot the forecasted values


plot(forecast(hw_model, h = 10), main = "Holt-Winters forecast")
Output:
2.Create a survey about VIT University with 5 questions and establish it to the
people who visits the VIT University using question pro (Add screenshot of
every steps carried out in the tool).

Step 1:
Output:


3.Explore Power bi tool with an excel workbook of Disney princesses, and
create a table from that (Add screenshot of every steps carried out in the tool).
4. Consider a multivariate dataset and create visualization on it using R.

CODE:
# Load the necessary libraries
library(ggplot2)
library(dplyr)

# Load the dataset


data(mtcars)

# Summarize the data


summary_data <- mtcars %>%
group_by(cyl) %>%
summarise(
avg_mpg = mean(mpg),
avg_hp = mean(hp),
avg_disp = mean(disp)
)

# Create a scatter plot of mpg (miles per gallon) vs hp (horsepower), colored by cyl (number of
cylinders)
ggplot(mtcars, aes(x = hp, y = mpg, color = factor(cyl))) +
geom_point() +
labs(title = "Scatterplot of mpg vs hp", x = "Horsepower", y = "Miles per Gallon", color = "Number
of Cylinders")

# Create a bar plot of average mpg for each number of cylinders


ggplot(summary_data, aes(x = factor(cyl), y = avg_mpg, fill = factor(cyl))) +
geom_bar(stat = "identity") +
labs(title = "Bar plot of average mpg by number of cylinders", x = "Number of Cylinders", y =
"Average Miles per Gallon", fill = "Number of Cylinders")
# Create a box plot of disp (displacement) for each number of cylinders
ggplot(mtcars, aes(x = factor(cyl), y = disp, fill = factor(cyl))) +
geom_boxplot() +
labs(title = "Box plot of displacement by number of cylinders", x = "Number of Cylinders", y =
"Displacement", fill = "Number of Cylinders")

You might also like