Plotting clusters of nominal data in R -
imagine have 7 categories (e.g. religion), , plot them not in linear way, in clusters automatically chosen nicely aligned. here individuals within groups have same response, should not plotted on 1 line (which happens when plotting ordinal data).
so sum up:
automatically using available graph space
grouping without order, spread around canvas
individuals remain visible; no overlapping
would nice have individuals within groups bound (invisible) circle
are there packages designed purpose? keywords need for?
example data:
religion <- sample(1:7, 100, t) # no overlap here, see group part come out more. plot(religion)
after assigning coordinates center of each group, can use wordcloud::textplot
avoid overlapping labels.
# data n <- 100 k <- 7 religion <- sample(1:k, n, true) names(religion) <- outer(letters, letters, paste0)[1:n] # position of groups x <- runif(k) y <- runif(k) # plot library(wordcloud) textplot( x[religion], y[religion], names(religion), xlim=c(0,1), ylim=c(0,1), axes=false, xlab="", ylab="" )
alternatively, can build graph clique (or tree) each group, , use 1 of many graph-layout algorithms in igraph
.
library(igraph) <- outer( religion, religion, `==` ) g <- graph.adjacency(a) plot(g) plot(minimum.spanning.tree(g))
Comments
Post a Comment