基于其他数据列的词云颜色
WordCloud color based on other data column
我想应用世界云函数,但要根据另一个属性更改颜色格式。
这是我的数据 d 的样子,显然我有更多的城市名称。
我的想法是,我希望根据频率的数量设置单词的大小,但单词的颜色基于 'year' 列。
这意味着巴黎和纽约的颜色相同,东京和罗马的颜色也相同。
name freq year status
paris 5 2010 booked
nyc 25 2010 booked
tokyo 10 2011 notbooked
rome 9 2011 notbooked
wordcloud(words = d$name, freq = d$freq, min.freq = 1,scale = c(2, 0.2),
max.words=200, random.order=FALSE, rot.per=0.1,
colors=brewer.pal(8, "Dark2"))
但是现在我不知道如何在 wordcloud 函数中引入 d$year。预先感谢您的帮助!
既然你说你想让东京和罗马有相同的颜色,我假设你打算让罗马的年份是 2011 年。
df=read.table(text="name freq year
paris 5 2010
nyc 25 2010
tokyo 10 2011
rome 9 2011",
header=TRUE)
library(wordcloud)
wordcloud(words = df$name, freq = df$freq, min.freq = 1,scale = c(2, 0.2),
max.words=200, random.order=FALSE, rot.per=0.1,
ordered.colors=TRUE,
colors=brewer.pal(8, "Dark2")[factor(df$year)])
我想应用世界云函数,但要根据另一个属性更改颜色格式。
这是我的数据 d 的样子,显然我有更多的城市名称。 我的想法是,我希望根据频率的数量设置单词的大小,但单词的颜色基于 'year' 列。 这意味着巴黎和纽约的颜色相同,东京和罗马的颜色也相同。
name freq year status
paris 5 2010 booked
nyc 25 2010 booked
tokyo 10 2011 notbooked
rome 9 2011 notbooked
wordcloud(words = d$name, freq = d$freq, min.freq = 1,scale = c(2, 0.2),
max.words=200, random.order=FALSE, rot.per=0.1,
colors=brewer.pal(8, "Dark2"))
但是现在我不知道如何在 wordcloud 函数中引入 d$year。预先感谢您的帮助!
既然你说你想让东京和罗马有相同的颜色,我假设你打算让罗马的年份是 2011 年。
df=read.table(text="name freq year
paris 5 2010
nyc 25 2010
tokyo 10 2011
rome 9 2011",
header=TRUE)
library(wordcloud)
wordcloud(words = df$name, freq = df$freq, min.freq = 1,scale = c(2, 0.2),
max.words=200, random.order=FALSE, rot.per=0.1,
ordered.colors=TRUE,
colors=brewer.pal(8, "Dark2")[factor(df$year)])