绘制巧克力棒的份额图
用图形展示能让份额预测更直观,也更容易理解。让我们绘制一个柱状图来展示这些份额。
本练习是课程的一部分
R 中的营销选择建模
练习说明
- 我已经写好第一行代码来计算份额,并将结果保存到
shares。 - 请补全
barplot()的缺失输入。第一个输入应为份额,存放在shares$share中。 - 第二个输入应为不同巧克力类型的名称,可从巧克力数据中获取:
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 = ____)