6
$\begingroup$

I'm trying to use Wordcloud built in function (I'm using v10.3.0.0) but the result is not good. I'm using a list with expressions and respective weights:

Scores={{"políticas ativas de emprego", 0.0105614189853},
{"envolvimento da comissão europeia",0.00847597097115},
{"procedimento de défice excessivo",0.00689428164087},
{"auxílios de estado", 0.00672761334329},
{"mercado interno de energia", 0.00651015550018},
{"cenário de políticas invariantes", 0.00616838495429},
{"termos _per capita_", 0.00528444675534},
{"fundo monetário internacional", 0.005156888605},
{"procedimento por défice excessivo", 0.00446366885149},
{"estado da portugal telecom", 0.00439010129432},
{"rácio de dívida pública", 0.00424150840713},
{"programa de assistência económica", 0.00421705550905},
{"_stock_ de dívida", 0.00373126508612},
{"informação da segurança social", 0.00367081223817},
{"tempo o partido socialista", 0.00363397022484},
{"caso da portugal telecom", 0.00349820427426},
{"_quantitative easing_", 0.00348106383557},
{"área da moeda única", 0.00346640013996},
{"portugal o partido socialista", 0.00334529581534},
{"introdução do quociente familiar",0.00330896979159},
{"banco espírito santo", 0.00326703397878},
{"questões do tribunal constitucional", 0.00289720906606},
{"serviço nacional de saúde", 0.00287941068182},
{"estatuto dos tribunais administrativos",0.00282062904814},
{"rendimento _per capita_", 0.00281631447877},
{"defesa da zona euro",0.002747796651},
{"exemplo o partido socialista", 0.00273072152925},
{"período na união europeia", 0.00250570307651},
{"área da fiscalidade verde",0.00248133473314},
{"governo regional dos açores", 0.00246743326021},
{"pano de fundo", 0.00245993070015},
{"dados da comissão europeia", 0.00245971711069},
{"resposta da segurança social", 0.00245027724487},
{"cimeira da zona euro", 0.00243492258733},
{"conselho de finanças públicas", 0.00234683012794},
{"empresa geral de fomento",0.00234021101473},
{"inação durante demasiados anos", 0.00229753939975},
{"caminho da espiral recessiva", 0.0022651746261},
{"aprofundamento da união económica",0.00225349666112},
{"caso do partido socialista", 0.00224751981847},
{"líder do partido socialista", 0.00222932489691},
{"endossadas pelo conselho europeu",0.00220717043396},
{"caso dos estaleiros navais", 0.0021845584449},
{"economia social de mercado", 0.00217228819124},
{"mundo cor de rosa", 0.00215947175436},
{"mobilidade geográfica dos trabalhadores", 0.00214962058393},
{"bilhetes do tesouro", 0.00214936829988},
{"projeção das contas públicas", 0.00211737006025},
{"_hub_ de lisboa", 0.0021145554114},
{"escola no decreto lei", 0.00209209131064}};

This is the result when using

WordCloud[Scores]

enter image description here

I get a "better" result with:

WordCloud[Scores, WordSpacings -> 20]

enter image description here

but in this case there is too much space between the words... So, how can make a nice wordcloud for this case?

EDIT: So this is what gives when using

WordCloud[Scores, WordSpacings -> {10, 8}]

enter image description here

and this is what I wish I had:

enter image description here

It was created using http://www.wordle.net/. I want to recreated it using Mathematica because I want to manipulate to colours, for which case Wordle is quite rigid in the options.

$\endgroup$
  • $\begingroup$ Closely related. Although I'd imagine even those solutions aren't optimise for phrases this long. $\endgroup$ – Martin Ender Mar 15 '16 at 15:04
  • $\begingroup$ What about values lower than 20? WordCloud[Scores, WordSpacings -> {10, 8}] looks nice to me $\endgroup$ – Jason B. Mar 15 '16 at 15:04
  • $\begingroup$ @MartinBüttner I was trying that solution before but it was taking a huge time to calculate any result. But thanks. $\endgroup$ – Miguel Mar 15 '16 at 15:54
  • $\begingroup$ @Miguel, this seems to be a regression, as I now get messy clouds with the same code that made clean ones in 10.2 I think. Can you contact WRI tech support? $\endgroup$ – alancalvitti Apr 15 '16 at 20:48
8
$\begingroup$

I find a decent result by using the two-argument version of WordSpacings, where the first number is along the word's direction (horizontal here) and the second is perpendicular to it (vertical here). Further, if I give it the same image dimensions as the wordle version above, the result is very similar

WordCloud[Scores, WordSpacings -> {10, 3}, ImageSize -> {1181, 498}]

enter image description here

And it is pretty easy to apply a custom color to each word. As far as I can tell the only argument given to ColorFunction is the weight, so we can't use that very easily), but we can use Style. Here is a list of random colors,

colorlist = RandomColor[Length@Scores]

enter image description here

Now I just apply Style to each word in the list,

WordCloud[
 MapIndexed[{Style[First@#1, colorlist[[#2]]], Last@#1} &, Scores], 
 WordSpacings -> {10, 3}, ImageSize -> {1181, 498}]

enter image description here

$\endgroup$
  • $\begingroup$ Ok, thanks. It is strange, because for that WordSpacings it still results a bit messy. I'm going to edit to show this result, and what I would like to give (from wordle). $\endgroup$ – Miguel Mar 15 '16 at 15:21
  • $\begingroup$ @Miguel - it matches the wordle result moreso now, but there's probably a different algorithm underneath. $\endgroup$ – Jason B. Mar 15 '16 at 15:43
  • $\begingroup$ Ok, thanks! Much better now. Now I need to colour each word with my own RGB list. Any idea if it is possible? $\endgroup$ – Miguel Mar 15 '16 at 15:52
  • $\begingroup$ @Miguel - as my daughter would say, "easy peasy lemon squeezy" $\endgroup$ – Jason B. Mar 15 '16 at 16:06
  • $\begingroup$ Nice! Thank you and your daughter. :) $\endgroup$ – Miguel Mar 15 '16 at 16:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.