MulaiMulai sekarang secara gratis

Multidimensional scaling in two dimensions

In this exercise, you will perform multidimensional scaling of state.x77 and plot the resulting object locations in a two dimensional space.

Latihan ini adalah bagian dari kursus

Multivariate Probability Distributions in R

Lihat Kursus

Petunjuk latihan

  • Compute the distance matrix and assign it to an object state.dist.
  • Compute the multidimensional scaling of the data on the distance matrix.
  • Use the ggplot() function to plot the representation of the state.x77 data in two dimensions. Color the state names by their region using the vector state.region.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# 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) 
Edit dan Jalankan Kode