Spaces:
Sleeping
Sleeping
Update app.R
Browse files
app.R
CHANGED
|
@@ -6,29 +6,6 @@ library(corrplot)
|
|
| 6 |
library(plotly)
|
| 7 |
library(gridExtra)
|
| 8 |
|
| 9 |
-
# データの読み込みと前処理
|
| 10 |
-
load_and_prepare_data <- function(file_path) {
|
| 11 |
-
# CSVファイルを読み込み
|
| 12 |
-
df <- read.csv(file_path, row.names = 1, check.names = FALSE)
|
| 13 |
-
|
| 14 |
-
# 行名を列に追加
|
| 15 |
-
df <- df %>%
|
| 16 |
-
mutate(年月 = rownames(df), .before = 1) %>%
|
| 17 |
-
rownames_to_column(var = "index") %>%
|
| 18 |
-
select(-index)
|
| 19 |
-
|
| 20 |
-
return(df)
|
| 21 |
-
}
|
| 22 |
-
|
| 23 |
-
# データを準備
|
| 24 |
-
data_file <- "SampleData.csv"
|
| 25 |
-
|
| 26 |
-
# アプリが実行されるディレクトリを確認して適切なパスを設定
|
| 27 |
-
if (!file.exists(data_file)) {
|
| 28 |
-
# Shinyサーバーで実行される場合のパス
|
| 29 |
-
data_file <- file.path(dirname(rstudioapi::getSourceEditorContext()$path), "SampleData.csv")
|
| 30 |
-
}
|
| 31 |
-
|
| 32 |
ui <- fluidPage(
|
| 33 |
# タイトルと概要
|
| 34 |
titlePanel("経営指標分析ダッシュボード"),
|
|
@@ -48,150 +25,148 @@ ui <- fluidPage(
|
|
| 48 |
tabsetPanel(
|
| 49 |
# タブ1: 相関分析
|
| 50 |
tabPanel("相関分析",
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
),
|
| 67 |
|
| 68 |
# タブ2: 回帰分析
|
| 69 |
tabPanel("回帰分析",
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
)
|
| 106 |
-
)
|
| 107 |
),
|
| 108 |
|
| 109 |
# タブ3: 時系列分析
|
| 110 |
tabPanel("時系列分析",
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
),
|
| 130 |
|
| 131 |
# タブ4: 統計サマリー
|
| 132 |
tabPanel("統計サマリー",
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
),
|
| 165 |
|
| 166 |
# タブ5: 詳細な散布図分析
|
| 167 |
tabPanel("詳細分析",
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
)
|
| 196 |
)
|
| 197 |
)
|
|
@@ -200,11 +175,12 @@ server <- function(input, output, session) {
|
|
| 200 |
|
| 201 |
# データの読み込み
|
| 202 |
df <- reactive({
|
| 203 |
-
# ファイルパスを設定(
|
| 204 |
possible_paths <- c(
|
| 205 |
-
"
|
| 206 |
-
|
| 207 |
-
"
|
|
|
|
| 208 |
)
|
| 209 |
|
| 210 |
for (path in possible_paths) {
|
|
@@ -227,7 +203,7 @@ server <- function(input, output, session) {
|
|
| 227 |
}
|
| 228 |
|
| 229 |
# ファイルが見つからない場合は警告
|
| 230 |
-
showNotification("SampleData.csvが見つかりません", type = "error")
|
| 231 |
return(NULL)
|
| 232 |
})
|
| 233 |
|
|
@@ -293,9 +269,9 @@ server <- function(input, output, session) {
|
|
| 293 |
|
| 294 |
# ヒートマップを作成
|
| 295 |
corrplot(corr_matrix, method = "color", type = "full",
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
}, error = function(e) {
|
| 300 |
plot(1, 1, type="n", xlab="", ylab="", main="エラー")
|
| 301 |
text(1, 1, paste("エラー:", e$message), cex=1.2, col="red")
|
|
@@ -333,11 +309,11 @@ server <- function(input, output, session) {
|
|
| 333 |
cat("相関係数が強い上位10の組み合わせ:\n\n")
|
| 334 |
for (i in 1:nrow(corr_pairs)) {
|
| 335 |
cat(sprintf("%s (%s) と %s (%s): %.3f\n",
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
}
|
| 342 |
}, error = function(e) {
|
| 343 |
cat("エラーが発生しました:", e$message)
|
|
@@ -376,9 +352,9 @@ server <- function(input, output, session) {
|
|
| 376 |
geom_point(size = 3, color = "steelblue", alpha = 0.6) +
|
| 377 |
geom_smooth(method = "lm", se = TRUE, color = "red", fill = "red", alpha = 0.2) +
|
| 378 |
labs(title = paste(y_label, "vs", x_label),
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
| 382 |
theme_minimal() +
|
| 383 |
theme(plot.title = element_text(hjust = 0.5, size = 14, face = "bold"))
|
| 384 |
|
|
@@ -410,9 +386,9 @@ server <- function(input, output, session) {
|
|
| 410 |
data <- df() %>%
|
| 411 |
select(年月, x9, x41, x56, x80) %>%
|
| 412 |
rename("整備営業利益" = x9,
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
|
| 416 |
gather(key = "部門", value = "営業利益", -年月)
|
| 417 |
|
| 418 |
p <- ggplot(data, aes(x = factor(年月, levels = unique(年月)),
|
|
@@ -422,12 +398,12 @@ server <- function(input, output, session) {
|
|
| 422 |
geom_line(size = 1) +
|
| 423 |
geom_point(size = 2) +
|
| 424 |
labs(title = "各部門の営業利益推移",
|
| 425 |
-
|
| 426 |
-
|
| 427 |
-
|
| 428 |
theme_minimal() +
|
| 429 |
theme(axis.text.x = element_text(angle = 45, hjust = 1),
|
| 430 |
-
|
| 431 |
|
| 432 |
ggplotly(p)
|
| 433 |
})
|
|
@@ -438,9 +414,9 @@ server <- function(input, output, session) {
|
|
| 438 |
data <- df() %>%
|
| 439 |
select(年月, x2, x37, x52, x76) %>%
|
| 440 |
rename("整備売上" = x2,
|
| 441 |
-
|
| 442 |
-
|
| 443 |
-
|
| 444 |
gather(key = "部門", value = "売上", -年月)
|
| 445 |
|
| 446 |
p <- ggplot(data, aes(x = factor(年月, levels = unique(年月)),
|
|
@@ -450,12 +426,12 @@ server <- function(input, output, session) {
|
|
| 450 |
geom_line(size = 1) +
|
| 451 |
geom_point(size = 2) +
|
| 452 |
labs(title = "各部門の売上高推移",
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
theme_minimal() +
|
| 457 |
theme(axis.text.x = element_text(angle = 45, hjust = 1),
|
| 458 |
-
|
| 459 |
|
| 460 |
ggplotly(p)
|
| 461 |
})
|
|
@@ -466,10 +442,10 @@ server <- function(input, output, session) {
|
|
| 466 |
data <- df() %>%
|
| 467 |
select(年月, x25, x31, x67, x73, x91) %>%
|
| 468 |
rename("車検件数" = x25,
|
| 469 |
-
|
| 470 |
-
|
| 471 |
-
|
| 472 |
-
|
| 473 |
gather(key = "KPI", value = "件数", -年月)
|
| 474 |
|
| 475 |
p <- ggplot(data, aes(x = factor(年月, levels = unique(年月)),
|
|
@@ -479,12 +455,12 @@ server <- function(input, output, session) {
|
|
| 479 |
geom_line(size = 1) +
|
| 480 |
geom_point(size = 2) +
|
| 481 |
labs(title = "KPI推移",
|
| 482 |
-
|
| 483 |
-
|
| 484 |
-
|
| 485 |
theme_minimal() +
|
| 486 |
theme(axis.text.x = element_text(angle = 45, hjust = 1),
|
| 487 |
-
|
| 488 |
|
| 489 |
ggplotly(p)
|
| 490 |
})
|
|
@@ -582,11 +558,11 @@ server <- function(input, output, session) {
|
|
| 582 |
|
| 583 |
# 散布図行列を作成
|
| 584 |
pairs(data_clean,
|
| 585 |
-
|
| 586 |
-
|
| 587 |
-
|
| 588 |
-
|
| 589 |
-
|
| 590 |
}, error = function(e) {
|
| 591 |
plot(1, 1, type="n", xlab="", ylab="")
|
| 592 |
text(1, 1, paste("エラー:", e$message), cex=1.2, col="red")
|
|
|
|
| 6 |
library(plotly)
|
| 7 |
library(gridExtra)
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
ui <- fluidPage(
|
| 10 |
# タイトルと概要
|
| 11 |
titlePanel("経営指標分析ダッシュボード"),
|
|
|
|
| 25 |
tabsetPanel(
|
| 26 |
# タブ1: 相関分析
|
| 27 |
tabPanel("相関分析",
|
| 28 |
+
fluidRow(
|
| 29 |
+
column(12,
|
| 30 |
+
h3("指標間の相関係数(ヒートマップ)"),
|
| 31 |
+
p("各ビジネス部門の売上、原価、粗利、営業利益、KPIなど全指標間の相関を表示します。")
|
| 32 |
+
)
|
| 33 |
+
),
|
| 34 |
+
fluidRow(
|
| 35 |
+
column(8, plotOutput("correlation_heatmap", height = "600px")),
|
| 36 |
+
column(4,
|
| 37 |
+
wellPanel(
|
| 38 |
+
h4("相関分析の概要"),
|
| 39 |
+
verbatimTextOutput("correlation_summary")
|
| 40 |
+
)
|
| 41 |
+
)
|
| 42 |
+
)
|
| 43 |
),
|
| 44 |
|
| 45 |
# タブ2: 回帰分析
|
| 46 |
tabPanel("回帰分析",
|
| 47 |
+
fluidRow(
|
| 48 |
+
column(12, h3("KPIと売上・利益の関係分析"))
|
| 49 |
+
),
|
| 50 |
+
fluidRow(
|
| 51 |
+
column(6,
|
| 52 |
+
wellPanel(
|
| 53 |
+
h4("回帰分析の設定"),
|
| 54 |
+
selectInput("x_var", "説明変数(X軸)",
|
| 55 |
+
c("整備_車検件数" = "x25",
|
| 56 |
+
"整備_整備・板金数" = "x31",
|
| 57 |
+
"運送_自社ドライバー数" = "x67",
|
| 58 |
+
"運送_他社ドライバー数" = "x73",
|
| 59 |
+
"レンタル_レンタル台数" = "x91")),
|
| 60 |
+
selectInput("y_var", "被説明変数(Y軸)",
|
| 61 |
+
c("整備_売上" = "x2",
|
| 62 |
+
"整備_営業利益" = "x9",
|
| 63 |
+
"商品_売上" = "x37",
|
| 64 |
+
"商品_営業利益" = "x41",
|
| 65 |
+
"運送_売上" = "x52",
|
| 66 |
+
"運送_営業利益" = "x56",
|
| 67 |
+
"レンタル_売上" = "x76",
|
| 68 |
+
"レンタル_営業利益" = "x80")),
|
| 69 |
+
actionButton("update_regression", "更新", class = "btn-primary")
|
| 70 |
+
)
|
| 71 |
+
)
|
| 72 |
+
),
|
| 73 |
+
fluidRow(
|
| 74 |
+
column(6, plotlyOutput("regression_scatter")),
|
| 75 |
+
column(6,
|
| 76 |
+
wellPanel(
|
| 77 |
+
h4("回帰分析結果"),
|
| 78 |
+
verbatimTextOutput("regression_results")
|
| 79 |
+
)
|
| 80 |
+
)
|
| 81 |
+
)
|
|
|
|
|
|
|
| 82 |
),
|
| 83 |
|
| 84 |
# タブ3: 時系列分析
|
| 85 |
tabPanel("時系列分析",
|
| 86 |
+
fluidRow(
|
| 87 |
+
column(12, h3("各部門の営業利益推移"))
|
| 88 |
+
),
|
| 89 |
+
fluidRow(
|
| 90 |
+
column(12, plotlyOutput("timeseries_profit", height = "500px"))
|
| 91 |
+
),
|
| 92 |
+
fluidRow(
|
| 93 |
+
column(12, h3("売上高の推移"))
|
| 94 |
+
),
|
| 95 |
+
fluidRow(
|
| 96 |
+
column(12, plotlyOutput("timeseries_sales", height = "500px"))
|
| 97 |
+
),
|
| 98 |
+
fluidRow(
|
| 99 |
+
column(12, h3("KPI推移"))
|
| 100 |
+
),
|
| 101 |
+
fluidRow(
|
| 102 |
+
column(12, plotlyOutput("timeseries_kpi", height = "500px"))
|
| 103 |
+
)
|
| 104 |
),
|
| 105 |
|
| 106 |
# タブ4: 統計サマリー
|
| 107 |
tabPanel("統計サマリー",
|
| 108 |
+
fluidRow(
|
| 109 |
+
column(12, h3("基本統計量"))
|
| 110 |
+
),
|
| 111 |
+
fluidRow(
|
| 112 |
+
column(6,
|
| 113 |
+
wellPanel(
|
| 114 |
+
h4("整備部門"),
|
| 115 |
+
verbatimTextOutput("summary_seisetsubi")
|
| 116 |
+
)
|
| 117 |
+
),
|
| 118 |
+
column(6,
|
| 119 |
+
wellPanel(
|
| 120 |
+
h4("商品部門"),
|
| 121 |
+
verbatimTextOutput("summary_shohin")
|
| 122 |
+
)
|
| 123 |
+
)
|
| 124 |
+
),
|
| 125 |
+
fluidRow(
|
| 126 |
+
column(6,
|
| 127 |
+
wellPanel(
|
| 128 |
+
h4("運送部門"),
|
| 129 |
+
verbatimTextOutput("summary_unsou")
|
| 130 |
+
)
|
| 131 |
+
),
|
| 132 |
+
column(6,
|
| 133 |
+
wellPanel(
|
| 134 |
+
h4("レンタル部門"),
|
| 135 |
+
verbatimTextOutput("summary_rental")
|
| 136 |
+
)
|
| 137 |
+
)
|
| 138 |
+
)
|
| 139 |
),
|
| 140 |
|
| 141 |
# タブ5: 詳細な散布図分析
|
| 142 |
tabPanel("詳細分析",
|
| 143 |
+
fluidRow(
|
| 144 |
+
column(12, h3("主���指標の散布図行列"))
|
| 145 |
+
),
|
| 146 |
+
fluidRow(
|
| 147 |
+
column(12,
|
| 148 |
+
wellPanel(
|
| 149 |
+
h4("分析対象指標の選択(複数選択可)"),
|
| 150 |
+
checkboxGroupInput("scatter_vars", "変数を選択",
|
| 151 |
+
c("整備_売上" = "x2",
|
| 152 |
+
"整備_粗利" = "x7",
|
| 153 |
+
"整備_営業利益" = "x9",
|
| 154 |
+
"商品_売上" = "x37",
|
| 155 |
+
"商品_粗利" = "x39",
|
| 156 |
+
"商品_営業利益" = "x41",
|
| 157 |
+
"運送_売上" = "x52",
|
| 158 |
+
"運送_粗利" = "x54",
|
| 159 |
+
"運送_営業利益" = "x56",
|
| 160 |
+
"レンタル_売上" = "x76",
|
| 161 |
+
"レンタル_粗利" = "x78",
|
| 162 |
+
"レンタル_営業利益" = "x80"),
|
| 163 |
+
selected = c("x2", "x9", "x37", "x52"))
|
| 164 |
+
)
|
| 165 |
+
)
|
| 166 |
+
),
|
| 167 |
+
fluidRow(
|
| 168 |
+
column(12, plotOutput("scatter_matrix", height = "800px"))
|
| 169 |
+
)
|
| 170 |
)
|
| 171 |
)
|
| 172 |
)
|
|
|
|
| 175 |
|
| 176 |
# データの読み込み
|
| 177 |
df <- reactive({
|
| 178 |
+
# ファイルパスを設定(Docker対応)
|
| 179 |
possible_paths <- c(
|
| 180 |
+
"DummyData.csv", # Docker環境
|
| 181 |
+
"SampleData.csv", # ローカル環境
|
| 182 |
+
file.path(getwd(), "DummyData.csv"),
|
| 183 |
+
file.path(getwd(), "SampleData.csv")
|
| 184 |
)
|
| 185 |
|
| 186 |
for (path in possible_paths) {
|
|
|
|
| 203 |
}
|
| 204 |
|
| 205 |
# ファイルが見つからない場合は警告
|
| 206 |
+
showNotification("DummyData.csv または SampleData.csv が見つかりません", type = "error")
|
| 207 |
return(NULL)
|
| 208 |
})
|
| 209 |
|
|
|
|
| 269 |
|
| 270 |
# ヒートマップを作成
|
| 271 |
corrplot(corr_matrix, method = "color", type = "full",
|
| 272 |
+
tl.cex = 0.7, tl.col = "black",
|
| 273 |
+
addCoef.col = "white", number.cex = 0.6,
|
| 274 |
+
title = "相関係数ヒートマップ", mar = c(0, 0, 2, 0))
|
| 275 |
}, error = function(e) {
|
| 276 |
plot(1, 1, type="n", xlab="", ylab="", main="エラー")
|
| 277 |
text(1, 1, paste("エラー:", e$message), cex=1.2, col="red")
|
|
|
|
| 309 |
cat("相関係数が強い上位10の組み合わせ:\n\n")
|
| 310 |
for (i in 1:nrow(corr_pairs)) {
|
| 311 |
cat(sprintf("%s (%s) と %s (%s): %.3f\n",
|
| 312 |
+
corr_pairs$var1_label[i],
|
| 313 |
+
corr_pairs$var1_code[i],
|
| 314 |
+
corr_pairs$var2_label[i],
|
| 315 |
+
corr_pairs$var2_code[i],
|
| 316 |
+
corr_pairs$correlation[i]))
|
| 317 |
}
|
| 318 |
}, error = function(e) {
|
| 319 |
cat("エラーが発生しました:", e$message)
|
|
|
|
| 352 |
geom_point(size = 3, color = "steelblue", alpha = 0.6) +
|
| 353 |
geom_smooth(method = "lm", se = TRUE, color = "red", fill = "red", alpha = 0.2) +
|
| 354 |
labs(title = paste(y_label, "vs", x_label),
|
| 355 |
+
subtitle = sprintf("(%s) vs (%s)", input$y_var, input$x_var),
|
| 356 |
+
x = x_label,
|
| 357 |
+
y = y_label) +
|
| 358 |
theme_minimal() +
|
| 359 |
theme(plot.title = element_text(hjust = 0.5, size = 14, face = "bold"))
|
| 360 |
|
|
|
|
| 386 |
data <- df() %>%
|
| 387 |
select(年月, x9, x41, x56, x80) %>%
|
| 388 |
rename("整備営業利益" = x9,
|
| 389 |
+
"商品営業利益" = x41,
|
| 390 |
+
"運送営業利益" = x56,
|
| 391 |
+
"レンタル営業利益" = x80) %>%
|
| 392 |
gather(key = "部門", value = "営業利益", -年月)
|
| 393 |
|
| 394 |
p <- ggplot(data, aes(x = factor(年月, levels = unique(年月)),
|
|
|
|
| 398 |
geom_line(size = 1) +
|
| 399 |
geom_point(size = 2) +
|
| 400 |
labs(title = "各部門の営業利益推移",
|
| 401 |
+
x = "年月",
|
| 402 |
+
y = "営業利益(円)",
|
| 403 |
+
color = "部門") +
|
| 404 |
theme_minimal() +
|
| 405 |
theme(axis.text.x = element_text(angle = 45, hjust = 1),
|
| 406 |
+
plot.title = element_text(hjust = 0.5, size = 14, face = "bold"))
|
| 407 |
|
| 408 |
ggplotly(p)
|
| 409 |
})
|
|
|
|
| 414 |
data <- df() %>%
|
| 415 |
select(年月, x2, x37, x52, x76) %>%
|
| 416 |
rename("整備売上" = x2,
|
| 417 |
+
"商品売上" = x37,
|
| 418 |
+
"運送売上" = x52,
|
| 419 |
+
"レンタル売上" = x76) %>%
|
| 420 |
gather(key = "部門", value = "売上", -年月)
|
| 421 |
|
| 422 |
p <- ggplot(data, aes(x = factor(年月, levels = unique(年月)),
|
|
|
|
| 426 |
geom_line(size = 1) +
|
| 427 |
geom_point(size = 2) +
|
| 428 |
labs(title = "各部門の売上高推移",
|
| 429 |
+
x = "年月",
|
| 430 |
+
y = "売上(円)",
|
| 431 |
+
color = "部門") +
|
| 432 |
theme_minimal() +
|
| 433 |
theme(axis.text.x = element_text(angle = 45, hjust = 1),
|
| 434 |
+
plot.title = element_text(hjust = 0.5, size = 14, face = "bold"))
|
| 435 |
|
| 436 |
ggplotly(p)
|
| 437 |
})
|
|
|
|
| 442 |
data <- df() %>%
|
| 443 |
select(年月, x25, x31, x67, x73, x91) %>%
|
| 444 |
rename("車検件数" = x25,
|
| 445 |
+
"整備・板金数" = x31,
|
| 446 |
+
"自社ドライバー数" = x67,
|
| 447 |
+
"他社ドライバー数" = x73,
|
| 448 |
+
"レンタル台数" = x91) %>%
|
| 449 |
gather(key = "KPI", value = "件数", -年月)
|
| 450 |
|
| 451 |
p <- ggplot(data, aes(x = factor(年月, levels = unique(年月)),
|
|
|
|
| 455 |
geom_line(size = 1) +
|
| 456 |
geom_point(size = 2) +
|
| 457 |
labs(title = "KPI推移",
|
| 458 |
+
x = "年月",
|
| 459 |
+
y = "件数・台数",
|
| 460 |
+
color = "KPI") +
|
| 461 |
theme_minimal() +
|
| 462 |
theme(axis.text.x = element_text(angle = 45, hjust = 1),
|
| 463 |
+
plot.title = element_text(hjust = 0.5, size = 14, face = "bold"))
|
| 464 |
|
| 465 |
ggplotly(p)
|
| 466 |
})
|
|
|
|
| 558 |
|
| 559 |
# 散布図行列を作成
|
| 560 |
pairs(data_clean,
|
| 561 |
+
panel = function(x, y, ...) {
|
| 562 |
+
points(x, y, col = "steelblue", cex = 0.7)
|
| 563 |
+
abline(lm(y ~ x), col = "red", lty = 2)
|
| 564 |
+
},
|
| 565 |
+
main = "変数間の散布図行列")
|
| 566 |
}, error = function(e) {
|
| 567 |
plot(1, 1, type="n", xlab="", ylab="")
|
| 568 |
text(1, 1, paste("エラー:", e$message), cex=1.2, col="red")
|