Reputation: 21
docnames(s1) <- rep(c("other","w"), each=6)
tmod_ca <- textmodel_ca(s1)
textplot_scale1d(tmod_ca)
dat_ca <- data.frame(dim1 = coef(tmod_ca, doc_dim = 1)$coef_document,
dim2 = coef(tmod_ca, doc_dim = 2)$coef_document)
head(dat_ca)
plot(1, xlim = c(-3, 3), ylim = c(-3, 3), type = "n", xlab = "Dimension 1", ylab = "Dimension 2")
grid()
text(dat_ca$dim1, dat_ca$dim2, labels = rownames(dat_ca), cex = 0.9, col = rgb(0, 0, 0, 0.7))
I want to see w1 - 6 and other1 - 6 in different colors. what should i do?
Upvotes: 0
Views: 56
Reputation: 11
I can't reproduce your example but I created a simple one:
data <- data.frame(
y = rnorm(12),
x = rnorm(12),
doc = rep(c("other","w"),each=6)
)
Then, you just need to add the argument col to your function test
, providing a vector of colors for each entry:
plot(data$x, data$y, type = "n")
text(data$x, data$y, data$doc, col = ifelse(grepl("other", data$doc), rgb(0, 0, 0, 0.7), rgb(0.5, 0.5, 0.5, 0.5)))
If you prefer a ggplot2 plot, there is the code:
require(ggplot2)
ggplot(data, aes(x = x, y = y)) + geom_text(aes(col = doc, label = doc))
Hope this helps
Upvotes: 1