為巧克力棒繪製占比圖
用圖像呈現能讓這些占比預測更有感,也更容易被理解。我們來畫一張長條圖來顯示各占比。
本練習屬於課程
R 的行銷選擇模型
練習說明
- 我已經寫好第一行程式碼,用來計算占比並將結果存成
shares。 - 你需要補上
barplot()缺少的輸入參數。第一個輸入應該是占比,已存放在shares$share。 - 第二個輸入應該是不同巧克力類型的名稱,可以從 chocolate 資料取得:
levels(chocolate$Type)
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# compute and save the share prediction
shares <- predict_mnl(choc_m2, ghir_choc)
# make a barplot of the shares
barplot(____,
horiz = TRUE, col="tomato2",
xlab = "Predicted Market Share",
main = "Shares for Ghiradelli chocolate bars at $3 each",
names.arg = ____)