数值变量与分类变量的可视化
如果解释变量是分类变量,那么之前用来可视化数据的散点图就不合适了。更好的做法是为每个类别分别绘制直方图。
台湾房地产数据集中有一个关于房龄的分类变量。房龄被分为 3 组:0–15 年、15–30 年和 30–45 年。
taiwan_real_estate 可用,且已加载 ggplot2。
本练习是课程的一部分
R 中的回归入门
练习说明
- 使用
taiwan_real_estate绘制price_twd_msq的直方图,设置10个箱数。 - 按
house_age_years分面,得到 3 个子图面板。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Using taiwan_real_estate, plot price_twd_msq
___ +
# Make it a histogram with 10 bins
___ +
# Facet the plot so each house age group gets its own panel
___