可视化数据集
在本练习中,您将使用 ggplot() 可视化您在前面练习中创建的复杂数据集。该数据集已存放在数据框 df 中。您无需可视化决策边界。
这里您将使用 coord_fixed(),使图中 x 轴与 y 轴采用相同的物理比例,从而让圆形呈现为圆形而非椭圆。
本练习是课程的一部分
R 中的支持向量机
练习说明
- 加载所需的绘图库。
- 设置
aesthetics参数中的映射。 - 为散点图设置合适的
geom_函数。 - 通过添加不带参数的
coord_fixed()来指定等比例坐标。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Load ggplot2
library(___)
# Plot x2 vs. x1, colored by y
scatter_plot<- ggplot(data = df, aes(x = ___, y = ___, color = ___)) +
# Add a point layer
geom___() +
scale_color_manual(values = c("red", "blue")) +
# Specify equal coordinates
coord_fixed()
scatter_plot