简体   繁体   中英

Multidimensional Scale in R - data

I would like to have a multidimensional scaling plot according to the following table (this is just a shorter form of the whole table).

I have been trying to do it in R (am quite new here...) but now. I am not even sure about that this type of data is good for multidimensional scaling. The whole table should mirror a semantic (linguistic) map (Thats why I thought that MDS should be good) and the rows mean that informants saw some pictures and gave different expressions (columns) for the pictures, so they described them differently. The numbers in the columns are no judgments in the sense that they are on a scale from 1 to 10 or something like that but they show how many people used the expression for pic1, pic2, and so forth.

Could anyone help me to explain that MDS is actually the appropriate model I am trying to use? (Sorry, I am just too much confused after reading a lot in the last days about different methods...) If so, here is the coding I used (just to be sure).

Thanks a lot for any advice!

daten <- structure(list(photos = c("p1", "p5", "p8", "p13", "p19", "p23", "p29", "p34", "p36", "p40", "p59", "p2", "p14"), expression1 = c(18,  8, 11, 15, 14, 16, 10, 12, 15, 18, 18, 0, 0), expression2 = c(0,  0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0), expression3 = c(0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0, 1, 1), expression4 = c(0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 15, 17), expression5 = c(0, 3, 5, 0, 0, 0,  1, 5, 1, 0, 0, 0, 0), expression6 = c(0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0), expression7 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0), expression8 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0)), row.names = c(NA, -13L), class = c("tbl_df", "tbl", "data.frame"))
library("tibble")
has_rownames(daten)
cr<-column_to_rownames(daten, var="photo")
has_rownames(cr)

matr_cr <- as.matrix(cr[,-1])
matr_cr
d<-dist(matr_cr)
fit <- cmdscale(d, eig = TRUE, k = 2)
x <- fit$points[, 1]
y <- fit$points[, 2]
plot(x, y, xlab="Coordinate 1", ylab="Coordinate 2",
 main="Multidimensional Scaling", type="n")
text(x, y, labels = row.names(matr_cr), cex=.6, col="red")
cr

Plotting multidimensional data is difficult and depending on the type of data and analysis is what to do. First of all, if you have several variables, it may be useful to cluster your data, one possible method is k-means that you can find it in the package "ClusterR". Another possible thing to do is to transform your variable by rotating the axis in order to lower the dimension with a Principal Component Analysis (PCA), you can find more about PCA in R in http://www.sthda.com/english/articles/31-principal-component-methods-in-r-practical-guide/

If you opp to plot your data as it is without a previous analysis, you may use ggplot2 package to make more useful and elegant plots. And to plot your different data attributes you can try changing size, color, shape, etc scales representing different dimensions. The problem with this option is that you can not plot several dimensions.

If I understand you well, you got pictures and people (informants) that make a review of the pictures. And the critics are separated in different levels (dimensions). If it is like that, you got as dimensions pictures, reviewers, and each level of the reviews, that make 2+N variables. Note that you can easily plot up to 5 dimensions in this kind of data, by setting x-axis and y-axis you got 2 dimensions, then you can use size scale for another dimension, color scale for another dimension, and the depending on your data and your preference you can use text or shape scale for the fifth dimension. I do not see in the table you provide the informants (reviewers) dimension. Further below you will found two examples of these plot using ggplot2, note that for shape scale a discrete variable must be used. In order to get beautiful plots and with meaning, you will have to try wich type of scale is better for each of your variables and will strongly depend on your data. Lastly, if you have several dimensions normally you should try first to assess if your data is clusterized or do a PCA.

library(ggplot2)
daten <- structure(list(photos = c("p1", "p5", "p8", "p13", "p19", "p23", "p29", "p34", "p36", "p40", "p59", "p2", "p14"), expression1 = c(18,  8, 11, 15, 14, 16, 10, 12, 15, 18, 18, 0, 0), expression2 = c(0,  0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0), expression3 = c(0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0, 1, 1), expression4 = c(0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 15, 17), expression5 = c(0, 3, 5, 0, 0, 0,  1, 5, 1, 0, 0, 0, 0), expression6 = c(0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0), expression7 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0), expression8 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0)), row.names = c(NA, -13L), class = c("tbl_df", "tbl", "data.frame"))

# with shape scale
ggplot(data = daten,aes(x=photos, y=expression1, col=expression2, size=expression3, shape=as.factor(expression4))) +
geom_point()

# with text scale
ggplot(data = daten,aes(x=expression4, y=expression1, col=expression2, size=expression3, label=photos)) +
geom_text()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM