0
votes

I'm producing a plot like this:

library(ggplot2)

data.dist = matrix(
  c(10, -10, 10, -10, 10, -10, 10, -10, 10),
  nrow=3,
  ncol=3,
  byrow = TRUE)

hc <- agnes(dist(data.dist), method = "ward", diss = TRUE)
cluster <- cutree(hc, k=2)
xy <- data.frame(cmdscale(dist(data.dist)), factor(cluster))
names(xy) <- c("x", "y", "cluster")
xy$model <- rownames(xy)

ggplot(xy, aes(x, y)) + geom_point(aes(colour=cluster), size=3)

Which gives me:

enter image description here

However, let's say I want to attach another covariate, say a binary variable c(1, 0, 1) to the data and display all 1 using one symbol (say an X) and all 0 using another symbol (say a dot). How can I accomplish this?

1
Map the shape aesthetic to your covariate. I suggest you study some ggplot2 tutorials. - Roland

1 Answers

1
votes
xy<-data.frame(x=rnorm(3),y=rnorm(3),cluster=as.factor(c(1,0,1)),another=as.factor(c(1,1,0)) )
ggplot(xy, aes(x, y,shape=another)) + geom_point(aes(colour=cluster), size=3)