# WordCloud: can words' style and orientation be functions of words?

Function WordCloud can take such options as WordOrientation and ColorFunction. It is not obvious how those word-stylings can depend on words themselves, for example semantic meaning of words or their linguistic (structural) properties. Is this possible at all?

NOTE: Originally posted on Wolfram Community. I am following @Mr.Wizard recommendation to make it a self-Q&A

-

WordCloud a recent function can do some neat tricks beyond the obvious. For example:

• Wrappers such as Style and Rotate passed to individual words will be preserved in the WordCloud
• These wrappers can be functions of words, for example their semantics or linguistics

Let's consider a list of top ranked baby names in 2015:

page = Import["http://www.babycenter.com/popularBabyNames.htm?year=2015", "Data"];

data = Flatten[{{#2, 1./#1}, {#3, 1./#1}} &
@@@Cases[page, {_Integer, ___String}, Infinity][[All, 1 ;; 3]], 1]


The simple code below will color and orient words differently depending on the gender deduced by machine learning function Classify:

WordCloud[{
If[Classify["NameGender", #] === "Male",
Rotate[Style[#1, Brown], Pi/4],
Rotate[Style[#1, Pink], -Pi/4]], #2} & @@@ data]


Quite impressive! But let's hook orientation and color to different variables. Color will still be gender, semantics, but let's link orientation with, say, length of the name. The longer the name the steeper the slope between $0$ and $2 \pi$. We need to find the range of lengths of words:

rng = StringLength /@ data[[All, 1]] // MinMax
(*{5,11}*)


and now with slight modification of code we get some beautiful and meaningful flow:

WordCloud[{
If[Classify["NameGender", #1] === "Male",
Rotate[Style[#1, Red], Pi/2 Rescale[StringLength[#1], rng]],
Rotate[Style[#1, Blue], Pi/2 Rescale[StringLength[#1], rng]]], #2} & @@@ data]


-
This is really cool! Thank you for sharing. Please excuse me while I go play with this now :-) – MarcoB Feb 27 at 22:41