As someone new to R, I am working at producing a word cloud that shows two variables: frequency
and rating
. Using a generic table, I am looking to display the hypothetical number of colleges (font = big to small in number) by state and the hypothetical average college rating
- 1 = green (good),
- 3 = yellow (average),
- 5 = red (bad)
I am able to to create this cloud that depicts fonts = number of colleges, but cannot tie in the rating to the third column. Here is my generic table:
State Colleges Rating
Alabama 220 1
Alaska 100 3
Arizona 50 5
Arkansas 275 1
California 155 3
Colorado 68 5
Connecticut 235 1
Delaware 189 3
Florida 32 5
Georgia 219 1
Hawaii 117 3
Idaho 63 5
Illinois 264 1
Indiana 167 3
Iowa 76 5
Kansas 287 1
Kentucky 178 3
Louisiana 67 5
Maine 246 1
Maryland 169 3
Massachusetts 46 5
Michigan 225 1
Minnesota 132 3
Mississippi 23 5
Missouri 219 1
Montana 194 3
Nebraska 97 5
Below is my very simple script:
library(wordcloud)
library(rcolorbrewer)
data <- read.csv("wordcloud.csv", header = T)
pal <- brewer.pal(9, "RdYlGn")
wordcloud(data$State, data$Colleges, scale = c(4,1), colors = pal, rot.per=.5)
The above script allows for text size to reflect number of colleges, but I am not able to link the color ramp of 1 = green (good) to 3 = yellow (average) to 5 = red (bad). Any suggestions are greatly appreciated.