开始使用免费开始使用

二维中的多维尺度分析

在本练习中,您将对 state.x77 执行多维尺度分析,并在二维空间中绘制得到的对象位置。

本练习是课程的一部分

R 中的多元概率分布

查看课程

练习说明

  • 计算距离矩阵,并将其赋给对象 state.dist
  • 在该距离矩阵上对数据进行多维尺度分析。
  • 使用 ggplot() 函数在二维中绘制 state.x77 数据的表示。使用向量 state.region 按地区为州名着色。

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Calculate distance 
state.dist <- dist(___)

# Perform multidimensional scaling 
mds.state <- cmdscale(___) 

# Change mds.state to a data frame for use in ggplot
mds.state_df <- data.frame(mds.state)

# Plot the representation of the data in two dimensions 
ggplot(data = ___, aes(x = X1, y = X2, label = rownames(mds.state), color = ____)) + 
    geom_text(alpha = 0.8, size = 3) 
编辑并运行代码