1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

RAdvent Calendar 2024

Day 11

Rを学びたい Step10(仮想データで実験)

Posted at

はじめに

Rを学びたいのStep10です。
仮想データを準備し、分析の練習をしていきます

データの準備

data.csv
Date,DayOfWeek,Sales,Weather,Promotion
2024-01-01,Monday,434,Rainy,None
2024-01-02,Tuesday,411,Rainy,Special Menu
2024-01-03,Wednesday,461,Rainy,Special Menu
2024-01-04,Thursday,748,Sunny,Discount
2024-01-05,Friday,627,Sunny,Special Menu
2024-01-06,Saturday,441,Rainy,Special Menu
2024-01-07,Sunday,659,Cloudy,Special Menu
2024-01-08,Monday,633,Sunny,Special Menu
2024-01-09,Tuesday,538,Rainy,Discount
2024-01-10,Wednesday,568,Cloudy,Special Menu
2024-01-11,Thursday,501,Rainy,Discount
2024-01-12,Friday,568,Rainy,None
2024-01-13,Saturday,425,Rainy,Discount
2024-01-14,Sunday,737,Sunny,Special Menu
2024-01-15,Monday,696,Sunny,None
2024-01-16,Tuesday,636,Sunny,Special Menu
2024-01-17,Wednesday,761,Sunny,Special Menu
2024-01-18,Thursday,786,Sunny,Discount
2024-01-19,Friday,454,Rainy,None
2024-01-20,Saturday,496,Rainy,Discount
2024-01-21,Sunday,641,Cloudy,Special Menu
2024-01-22,Monday,794,Sunny,Discount
2024-01-23,Tuesday,549,Rainy,Discount
2024-01-24,Wednesday,639,Sunny,Discount
2024-01-25,Thursday,466,Rainy,None
2024-01-26,Friday,690,Sunny,None
2024-01-27,Saturday,411,Rainy,Special Menu
2024-01-28,Sunday,638,Sunny,Discount
2024-01-29,Monday,615,Sunny,Special Menu
2024-01-30,Tuesday,632,Cloudy,Special Menu

分析

まずは箱ひげ図を作って行こうと思います。

# 必要なライブラリを読み込み
library(tidyverse)

# データの読み込み
data <- read.csv("cafe_sales_data.csv")

# 箱ひげ図の作成
ggplot(data, aes(x = Weather, y = Sales, fill = Weather)) +
  geom_boxplot() +
  labs(title = "Sales by Weather Condition", x = "Weather", y = "Sales") +
  theme_minimal()

image.png

・曇りの日
 ・中央値は640ドル。
 ・四分位範囲(IQR): 約 625ドル〜645ドル
・外れ値が570ドル

・雨の日
 ・中央値は460ドル。
 ・四分位範囲(IQR): 約 430ドル〜500ドル
 
・晴れの日
 ・中央値は680ドル
・四分位範囲(IQR): 約 640ドル〜750ドル

棒グラフ

# 必要なライブラリを読み込み
library(tidyverse)

# データの読み込み
data <- read.csv("cafe_sales_data.csv")

# 平均売上を計算
avg_sales <- data %>%
  group_by(Weather) %>%
  summarize(AverageSales = mean(Sales))

# 棒グラフを作成
ggplot(avg_sales, aes(x = Weather, y = AverageSales, fill = Weather)) +
  geom_bar(stat = "identity") +
  labs(title = "Average Sales by Weather Condition", x = "Weather", y = "Average Sales") +
  theme_minimal()

image.png

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?