Reputation: 444
I am working in R
with the package smacof
.
I have a on which I would like to see the points 1 to 10 in Red, and the others leave black.
I made it with the following commands:
nations_indscal2<-smacofIndDiff(nations_list, ndim=2, metric=FALSE,
constraint="indscal",itmax=10000)
nations_indscal2$gspace
plot(nations_indscal2)
nations_indscal2$cweights
weightspace(nations_indscal2,20,1,2)
I tried (for point 1):
text(nations_indscal2$cweights[[1]], col="red")
weightspace(nations_indscal2,20,1,2)
I get no error, but it doesn't work either. Any ideas where I am wrong?
Please find a reproducible example of the nations_list
here:
list(structure(c(6, 1, 6, 6, 5, 8, 6, 7, 5, 6, 5, 5, 7, 8, 8,
8, 8, 7, 6, 7, 8, 7, 3, 5, 8, 6, 5, 8, 8, 7, 8, 2, 5, 6, 1, 8,
5, 3, 7, 4, 7, 1, 2, 3, 8), Labels = c("Brazil", "Congo", "Cuba",
"Egypt", "France", "India", "Israel", "Japan", "China", "USA"
), Size = 10L, call = as.dist.default(m = data, diag = TRUE,
upper = FALSE), class = "dist", Diag = TRUE, Upper = FALSE),
structure(c(6, 1, 6, 6, 5, 8, 6, 7, 5, 6, 5, 5, 7, 8, 8,
8, 8, 7, 6, 7, 8, 7, 3, 5, 8, 6, 5, 8, 8, 7, 8, 2, 5, 6,
1, 8, 5, 3, 7, 4, 7, 1, 2, 3, 8), Labels = c("Brazil", "Congo",
"Cuba", "Egypt", "France", "India", "Israel", "Japan", "China",
"USA"), Size = 10L, call = as.dist.default(m = data, diag = TRUE,
upper = FALSE), class = "dist", Diag = TRUE, Upper = FALSE),
structure(c(6, 5, 5, 5, 5, 6, 5, 5, 5, 6, 5, 6, 5, 6, 6,
6, 6, 6, 5, 7, 6, 6, 5, 5, 6, 4, 4, 6, 6, 6, 6, 5, 6, 6,
2, 6, 5, 4, 5, 4, 6, 3, 3, 3, 6), Labels = c("Brazil", "Congo",
"Cuba", "Egypt", "France", "India", "Israel", "Japan", "China",
"USA"), Size = 10L, call = as.dist.default(m = data, diag = TRUE,
upper = FALSE), class = "dist", Diag = TRUE, Upper = FALSE),
structure(c(7, 5, 6, 7, 7, 7, 6, 7, 6, 7, 4, 5, 7, 7, 7,
7, 7, 7, 7, 8, 7, 7, 7, 7, 5, 7, 7, 7, 8, 5, 7, 6, 8, 7,
5, 7, 7, 4, 7, 6, 7, 4, 4, 5, 6), Labels = c("Brazil", "Congo",
"Cuba", "Egypt", "France", "India", "Israel", "Japan", "China",
"USA"), Size = 10L, call = as.dist.default(m = data, diag = TRUE,
upper = FALSE), class = "dist", Diag = TRUE, Upper = FALSE),
structure(c(7, 5, 7, 5, 3, 7, 4, 3, 4, 7, 6, 6, 7, 7, 7,
7, 8, 7, 6, 6, 7, 6, 4, 5, 7, 7, 7, 7, 8, 7, 7, 6, 5, 6,
1, 6, 4, 2, 5, 7, 6, 7, 1, 5, 5), Labels = c("Brazil", "Congo",
"Cuba", "Egypt", "France", "India", "Israel", "Japan", "China",
"USA"), Size = 10L, call = as.dist.default(m = data, diag = TRUE,
upper = FALSE), class = "dist", Diag = TRUE, Upper = FALSE),
structure(c(7, 5, 7, 7, 7, 7, 7, 7, 6, 7, 6, 6, 7, 7, 7,
7, 8, 7, 7, 7, 7, 7, 7, 5, 6, 5, 6, 7, 6, 7, 7, 7, 6, 7,
5, 6, 7, 6, 7, 7, 7, 6, 4, 7, 7), Labels = c("Brazil", "Congo",
"Cuba", "Egypt", "France", "India", "Israel", "Japan", "China",
"USA"), Size = 10L, call = as.dist.default(m = data, diag = TRUE,
upper = FALSE), class = "dist", Diag = TRUE, Upper = FALSE),
structure(c(5, 3, 4, 7, 2, 3, 6, 3, 6, 4, 6, 7, 5, 4, 6,
6, 7, 1, 5, 2, 4, 6, 4, 3, 5, 4, 2, 5, 5, 6, 6, 5, 4, 3,
1, 5, 4, 4, 5, 5, 6, 6, 3, 2, 2), Labels = c("Brazil", "Congo",
"Cuba", "Egypt", "France", "India", "Israel", "Japan", "China",
"USA"), Size = 10L, call = as.dist.default(m = data, diag = TRUE,
upper = FALSE), class = "dist", Diag = TRUE, Upper = FALSE),
structure(c(6, 5, 6, 5, 4, 7, 7, 6, 6, 5, 5, 6, 6, 8, 8,
7, 7, 7, 7, 7, 8, 8, 6, 7, 5, 6, 5, 8, 7, 7, 7, 5, 6, 7,
4, 8, 6, 6, 6, 7, 7, 3, 4, 5, 6), Labels = c("1", "2", "3",
"4", "5", "6", "7", "8", "9", "10"), Size = 10L, call = as.dist.default(m = data,
diag = TRUE, upper = FALSE), class = "dist", Diag = TRUE, Upper = FALSE),
structure(c(5, 3, 6, 7, 6, 6, 7, 6, 6, 6, 5, 7, 6, 7, 6,
7, 7, 7, 7, 6, 6, 7, 6, 6, 7, 6, 5, 7, 7, 8, 7, 7, 6, 7,
3, 5, 5, 5, 7, 6, 6, 7, 1, 6, 6), Labels = c("Brazil", "Congo",
"Cuba", "Egypt", "France", "India", "Israel", "Japan", "China",
"USA"), Size = 10L, call = as.dist.default(m = data, diag = TRUE,
upper = FALSE), class = "dist", Diag = TRUE, Upper = FALSE),
structure(c(4, 2, 2, 6, 6, 3, 8, 7, 6, 1, 2, 8, 4, 2, 8,
7, 7, 7, 7, 7, 7, 8, 4, 8, 7, 1, 2, 8, 2, 8, 8, 8, 8, 8,
2, 7, 7, 1, 8, 8, 7, 8, 2, 3, 8), Labels = c("Brazil", "Congo",
"Cuba", "Egypt", "France", "India", "Israel", "Japan", "China",
"USA"), Size = 10L, call = as.dist.default(m = data, diag = TRUE,
upper = FALSE), class = "dist", Diag = TRUE, Upper = FALSE),
structure(c(3, 3, 4, 5, 3, 5, 6, 6, 6, 4, 2, 4, 5, 5, 5,
2, 7, 3, 4, 3, 5, 2, 3, 7, 6, 3, 4, 7, 5, 2, 5, 6, 8, 3,
7, 7, 7, 7, 7, 7, 5, 8, 2, 7, 1), Labels = c("Brazil", "Congo",
"Cuba", "Egypt", "France", "India", "Israel", "Japan", "China",
"USA"), Size = 10L, call = as.dist.default(m = data, diag = TRUE,
upper = FALSE), class = "dist", Diag = TRUE, Upper = FALSE),
structure(c(7, 6, 7, 7, 7, 8, 8, 8, 6, 7, 6, 6, 8, 8, 8,
8, 8, 8, 8, 7, 8, 8, 5, 8, 8, 8, 6, 8, 8, 8, 8, 4, 5, 8,
2, 8, 7, 7, 8, 5, 8, 2, 7, 3, 8), Labels = c("Brazil", "Congo",
"Cuba", "Egypt", "France", "India", "Israel", "Japan", "China",
"USA"), Size = 10L, call = as.dist.default(m = data, diag = TRUE,
upper = FALSE), class = "dist", Diag = TRUE, Upper = FALSE),
structure(c(5, 3, 4, 4, 4, 6, 3, 4, 4, 4, 5, 4, 5, 5, 4,
3, 4, 2, 4, 4, 4, 5, 2, 7, 4, 4, 6, 4, 2, 5, 4, 4, 4, 3,
3, 3, 4, 3, 2, 5, 4, 1, 4, 1, 5), Labels = c("Brazil", "Congo",
"Cuba", "Egypt", "France", "India", "Israel", "Japan", "China",
"USA"), Size = 10L, call = as.dist.default(m = data, diag = TRUE,
upper = FALSE), class = "dist", Diag = TRUE, Upper = FALSE),
structure(c(6, 6, 7, 5, 7, 7, 6, 7, 6, 6, 6, 3, 6, 7, 7,
6, 7, 2, 6, 4, 6, 7, 2, 7, 4, 4, 5, 4, 2, 4, 6, 4, 2, 7,
3, 6, 7, 3, 7, 3, 6, 2, 6, 2, 6), Labels = c("Brazil", "Congo",
"Cuba", "Egypt", "France", "India", "Israel", "Japan", "China",
"USA"), Size = 10L, call = as.dist.default(m = data, diag = TRUE,
upper = FALSE), class = "dist", Diag = TRUE, Upper = FALSE),
structure(c(6, 6, 7, 8, 6, 6, 7, 7, 8, 7, 6, 8, 6, 6, 7,
7, 8, 7, 8, 7, 8, 4, 3, 8, 7, 6, 5, 7, 7, 7, 8, 7, 7, 8,
2, 6, 7, 6, 8, 7, 7, 8, 1, 8, 8), Labels = c("Brazil", "Congo",
"Cuba", "Egypt", "France", "India", "Israel", "Japan", "China",
"USA"), Size = 10L, call = as.dist.default(m = data, diag = TRUE,
upper = FALSE), class = "dist", Diag = TRUE, Upper = FALSE),
structure(c(8, 7, 7, 7, 8, 7, 7, 8, 7, 7, 7, 6, 7, 8, 8,
8, 8, 7, 8, 7, 7, 6, 6, 8, 7, 7, 6, 7, 7, 7, 7, 6, 7, 8,
6, 6, 7, 7, 7, 8, 8, 6, 5, 8, 8), Labels = c("Brazil", "Congo",
"Cuba", "Egypt", "France", "India", "Israel", "Japan", "China",
"USA"), Size = 10L, call = as.dist.default(m = data, diag = TRUE,
upper = FALSE), class = "dist", Diag = TRUE, Upper = FALSE),
structure(c(6, 4, 6, 4, 5, 5, 6, 6, 7, 4, 5, 7, 6, 7, 5,
5, 8, 5, 7, 7, 4, 5, 2, 8, 5, 5, 4, 5, 5, 7, 7, 6, 3, 7,
2, 3, 4, 6, 6, 6, 4, 7, 3, 6, 8), Labels = c("Brazil", "Congo",
"Cuba", "Egypt", "France", "India", "Israel", "Japan", "China",
"USA"), Size = 10L, call = as.dist.default(m = data, diag = TRUE,
upper = FALSE), class = "dist", Diag = TRUE, Upper = FALSE),
structure(c(5, 2, 6, 6, 7, 6, 7, 7, 5, 5, 4, 7, 5, 6, 7,
7, 7, 7, 7, 6, 6, 6, 7, 7, 6, 7, 3, 6, 5, 8, 7, 7, 7, 6,
3, 4, 4, 3, 7, 5, 7, 7, 0, 6, 7), Labels = c("Brazil", "Congo",
"Cuba", "Egypt", "France", "India", "Israel", "Japan", "China",
"USA"), Size = 10L, call = as.dist.default(m = data, diag = TRUE,
upper = FALSE), class = "dist", Diag = TRUE, Upper = FALSE),
structure(c(7, 5, 5, 6, 6, 6, 6, 5, 6, 5, 5, 7, 7, 7, 6,
5, 7, 4, 8, 6, 8, 6, 4, 8, 5, 5, 6, 6, 5, 7, 4, 2, 4, 7,
1, 5, 4, 4, 6, 5, 6, 0, 2, 5, 8), Labels = c("Brazil", "Congo",
"Cuba", "Egypt", "France", "India", "Israel", "Japan", "China",
"USA"), Size = 10L, call = as.dist.default(m = data, diag = TRUE,
upper = FALSE), class = "dist", Diag = TRUE, Upper = FALSE),
structure(c(4, 1, 2, 7, 2, 3, 1, 1, 8, 2, 1, 8, 2, 2, 2,
1, 7, 1, 7, 1, 1, 0, 0, 7, 7, 2, 2, 2, 0, 8, 8, 8, 8, 8,
2, 1, 1, 0, 6, 2, 0, 7, 1, 8, 8), Labels = c("Brazil", "Congo",
"Cuba", "Egypt", "France", "India", "Israel", "Japan", "China",
"USA"), Size = 10L, call = as.dist.default(m = data, diag = TRUE,
upper = FALSE), class = "dist", Diag = TRUE, Upper = FALSE))
Upvotes: 1
Views: 239
Reputation: 121608
I rewrite your weightspace function:
nindividuals <- 15
weights <- sapply(nations_indscal2$cweights[1:nindividuals],diag)
plot(x=weights[1,],y = weights[2,],type ='n')
text(x=weights[1,],y = weights[2,],
labels = seq(1,nindividuals),cex=1,col = c(rep('red',10),rep(1,6)))
Upvotes: 2