π Full Name: Dorothy Pierandrri π Student ID: 702688145
Sales DatasetInstructions:
- Load the necessary packages: ggplot2,
dplyr.
- Load the Sales.csv dataset.
- Retrieve the number of columns and
rows in the dataset.
- Use str() to examine the structure of
the dataset.
- Use glimpse() for a quick overview of
the dataset.
π Need help? Refer to Slides 4-5 of Lecture 12 for guidance.
library(ggplot2)
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
Sales <- read.csv("Sales.csv")
ncol(Sales)
## [1] 3
nrow(Sales)
## [1] 24
str(Sales)
## 'data.frame': 24 obs. of 3 variables:
## $ Year : chr "Y2021" "Y2021" "Y2021" "Y2021" ...
## $ Month: int 1 2 3 4 5 6 7 8 9 10 ...
## $ Sales: int 11110 18816 15307 11491 15971 16916 15762 15983 14226 12601 ...
glimpse(Sales)
## Rows: 24
## Columns: 3
## $ Year <chr> "Y2021", "Y2021", "Y2021", "Y2021", "Y2021", "Y2021", "Y2021", "β¦
## $ Month <int> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9β¦
## $ Sales <int> 11110, 18816, 15307, 11491, 15971, 16916, 15762, 15983, 14226, 1β¦
Instructions:
- Create a line graph to visualize the relationship
between Month and Sales, grouped by
Year.
- Modify the line type and color based
on the Year variable.
- Adjust the line width to 0.7.
- Add data points, distinguishing years by
color and shape.
- Set the point size to 2.
- Label the x-axis as "Months".
- Label the y-axis as "Sales".
- Add a plot title:
"Sales Comparison".
- Add a plot subtitle:
"Year 2021 & 2022".
- Apply the classic theme to the plot.
- Center-align the title and subtitle.
π Need help? Refer to Slides 16-17 of Lecture 12 for guidance.
ggplot(data=Sales, aes(x=Month, y= Sales,group=Year )) +
geom_line(aes(linetype= Year, color= Year), size=2) +
geom_point(aes(color= Year, shape=Year),size=2) +
labs (x= "Months" ,y="Sales",
title = "Sales Comparison",
subtitle = "Yeard 2021 & 2022") +
theme_classic() +
theme(plot.title = element_text(hjust = 0.5),
plot.subtitle = element_text(hjust = 0.5))
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## βΉ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
Instructions:
- Save the line graph created in Task
2 as an image file.
- Name the file βSales_Trend_Comparison.jpgβ.
π Need help? Refer to Slide 18 of Lecture 12 for guidance.
#Save the line graph as an image file
ggsave("Sales_Trend_Comparison.jpg")
## Saving 7 x 5 in image
β
Save your work.
β
Knit your R Notebook as an HTML
file.
β Do NOT submit the .Rmd file.
Upload the following two files:
1οΈβ£ YourFirstName_YourLastName - In-Class Assignment
08.html
2οΈβ£ Sales_Trend_Comparison.jpg
π Double-check your files before submitting!