wordlayout {wordcloud}R Documentation

Word Layout

Description

finds text plot layout coordinates such that no text overlaps

Usage

wordlayout(x, y, words, cex=1, rotate90 = FALSE,
		xlim=c(-Inf,Inf), ylim=c(-Inf,Inf), tstep=.1, rstep=.1, ...)

Arguments

x

x coordinates

y

y coordinates

words

the text to plot

cex

font size

rotate90

a value or vector indicating whether words should be rotated 90 degrees

xlim

x axis bounds for text

ylim

y axis bounds for text

tstep

the angle (theta) step size as the algorithm spirals out

rstep

the radius step size (in standard deviations) as the algorithm spirals out

...

Additional parameters to be passed to strwidth and strheight.

Value

A matrix with columns representing x, y width and height.

Examples


#calculate standardized MDS coordinates
dat <- sweep(USArrests,2,colMeans(USArrests))
dat <- sweep(dat,2,sqrt(diag(var(dat))),"/")
loc <- cmdscale(dist(dat))
x <- loc[,1]
y <- loc[,2]
w <- rownames(loc)

#plot with no overlap and all words visible
plot(x,y,type="n",xlim=c(-3,3),ylim=c(-3,2))
lay <- wordlayout(x,y,w,xlim=c(-3,3),ylim=c(-3,2))
text(lay[,1]+.5*lay[,3],lay[,2]+.5*lay[,4],w)

#notice north dakota is only partially visible
textplot(x,y,w)


[Package wordcloud version 2.6 Index]