Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple word cloud example in R
wordper25k democrats republicans
millionaires 7 0
arithmetic 3 0
equal pay 6 0
level playing field 2 0
bin laden 5 0
auto 18 1
fair 13 1
middle class 47 7
forward 33 6
medicaid 2 0
wall street 5 1
workers 19 4
health 38 9
veteran 16 2
seniors 11 3
fight 39 11
medicare 26 7
obama 175 66
education 33 10
invest 22 7
women 69 26
military 12 5
vote 29 11
choice 22 15
science 2 1
biden 11 6
families 66 54
energy 20 13
war 19 9
economy 53 41
tax 39 32
immigration 10 10
jobs 88 80
hope 17 19
oil/gas 11 10
ryan 25 31
god 22 35
romney 92 109
american dream 17 20
marry 6 8
small businesses 14 27
better 21 44
leadership 32 53
debt 13 21
success 20 44
freedom 8 21
faith 6 11
obamacare 4 11
business 35 86
spending 7 15
fail 6 11
government 13 66
job creators 1 5
flag 1 4
regulation 2 14
church 1 9
unemployment 1 17
red tape 0 3
library(wordcloud)
library(RColorBrewer)
conventions <- read.table("conventions.csv",
header = TRUE,
sep = ",")
png("dnc.png")
wordcloud(conventions$wordper25k, # words
conventions$democrats, # frequencies
scale = c(4,1), # size of largest and smallest words
colors = brewer.pal(9,"Blues"), # number of colors, palette
rot.per = 0) # proportion of words to rotate 90 degrees
dev.off()
png("rnc.png")
wordcloud(conventions$wordper25k,
conventions$republicans,
scale = c(4,1),
colors = brewer.pal(9,"Reds"),
rot.per = 0)
dev.off()
@padmt1112

This comment has been minimized.

Copy link

@padmt1112 padmt1112 commented Jul 6, 2014

Just before dev.off (), I get the following error

Error in -freq : invalid argument to unary operator
In addition: Warning message:
In max(freq) : no non-missing arguments to max; returning -Inf

@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Nov 12, 2014

@padmt1112 one of the values you're passing in as a parameter is null. You need to make sure your column headers are correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment