1
votes
require(wordcloud)
textplot(loc[,1],loc[,2],states)

Gives me this

http://blog.fellstat.com/wp-content/uploads/2012/09/blog_text2.png

I want to change the colour of the red dots.

    textplot(loc[,1],loc[,2],states, col="blue")

This changes the colour of the text.

Somwehre in the texplot function is the code for points:

    > textplot
    function (x, y, words, cex = 1, new = TRUE, show.lines = TRUE, 
....
                    points(x[i], y[i], pch = 16, col = "red", cex = 0.5)
....
 <environment: namespace:wordcloud>

But does this mean it's fixed to red, pch 16 and cex 0.5? I changed the par to par(col="blue") and it still shows the red dots.

1

1 Answers

2
votes

It is unfortunately hard coded into the function. You can just modify the function somewhere in your scripts to implement this.

library(wordcloud)
dat <- sweep(USArrests, 2, colMeans(USArrests))
dat <- sweep(dat, 2, sqrt(diag(var(dat))),"/")
loc <- cmdscale(dist(dat))


    textplot2 <- function(x, 
                      y, 
                      words, 
                      cex = 1, 
                      pch = 16, 
                      pointcolor = "red", 
                      new = TRUE,
                      show.lines=TRUE, 
                      ...){
  if(new)
    plot(x,y,type="n",...)
  lay <- wordlayout(x,y,words,cex,...)
  if(show.lines){
    for(i in 1:length(x)){
      xl <- lay[i,1]
      yl <- lay[i,2]
      w <- lay[i,3]
      h <- lay[i,4]
      if(x[i]<xl || x[i]>xl+w ||
         y[i]<yl || y[i]>yl+h){
        points(x[i],y[i],pch= pch,col= pointcolor,cex= .5)
        nx <- xl+.5*w
        ny <- yl+.5*h
        lines(c(x[i],nx),c(y[i],ny),col="grey")
      }
    }
  }
  text(lay[,1]+.5*lay[,3],lay[,2]+.5*lay[,4],words,cex = cex,...)
}

Then call the new textplot2

textplot2(loc[,1],loc[,2],rownames(loc),pch = 16, pointcolor = "blue")