#1. Using the MakeupDB.xlsx dataset, create an area plot with Months on the x-axis, Dollars
#an the y-axis, and Product as the category. Note: you will have to summarize the data by
#month as a sum by month and product.
# Load required libraries
library(readxl)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(plotly)
## Loading required package: ggplot2
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
# Step 1: Load the dataset
df <- read_excel('MakeupDB.xlsx')
# Step 2: Summarize the data by month
df_summary <- df %>%
mutate(Month = format(Date, "%Y-%m")) %>%
group_by(Month, Product) %>%
summarise(Total_Dollars = sum(Dollars))
## `summarise()` has grouped output by 'Month'. You can override using the
## `.groups` argument.
# Step 3: Create the area plot with Plotly
plot_ly(df_summary, x = ~Month, y = ~Total_Dollars, fill = ~Product, type = 'scatter', mode = 'stack') %>%
layout(title = "Monthly Makeup Sales by Product",
xaxis = list(title = "Months"),
yaxis = list(title = "Dollars"),
showlegend = TRUE)
#2. Using the Sales by Region.xlsx dataset, create a bubble chart with Number of Projects on
#the x-axis, Percentage of Sales on the y-axis, the size of the bubble using Sales, and each
#bubble’s color using Sales Region.
# Step 1: Load the dataset
df <- read_excel("Sales by Region.xlsx")
# Step 2: Prepare the data
# Number of Products on the x-axis and Percentage of Sales on the y-axis,
# we'll directly use the columns from the dataset.
x <- df$`Number of Products`
y <- df$`Percentage of Market Share`
sales <- df$Sales
region <- df$`Sales Region`
# Step 3: Create the bubble chart with Plotly
plot_ly(x = x, y = y, size = sales, color = region, text = region) %>%
add_markers() %>%
layout(
xaxis = list(title = "Number of Products"),
yaxis = list(title = "Percentage of Sales"),
title = "Bubble Chart: Sales by Region",
showlegend = TRUE
)