在tagcloud中保留大写

时间:2016-06-13 12:46:56

标签: r tag-cloud

我想制作一个标签云来显示基因频率。

library(wordcloud)

genes_snv <- read.csv("genes.txt", sep="", header=FALSE)

wordcloud(genes_snv$V1,
          min.freq=15,
          scale=c(5,0.5),
          max.words=100,
          random.order=FALSE,
          rot.per=0.3,
          colors=brewer.pal(8, "Dark2"))

这是我的代码,但它将所有内容转换为小写(对基因名称无用)。我怎么能避免这个?

genes.txt

开头
Fcrl5
Etv3
Etv3
Lrrc71
Lrrc71
(...)

1 个答案:

答案 0 :(得分:2)

freq参数丢失时wordcloud调用tm::TermDocumentMatrix,我猜在计算频率之前内部调用函数tolower

为避免拨打tm,我们可以提供自己的频率,请参阅示例:

# dummy data
set.seed(1)
genes <- c("Fcrl5","Etv3","Etv3","Lrrc71","Lrrc71")
genes <- unlist(sapply(genes, function(i)rep(i, sample(1:100,1))))

# get frequency
plotDat <- as.data.frame(table(genes))

# plot
wordcloud(word = plotDat$genes, freq = plotDat$Freq,
          min.freq=15,
          scale=c(5,0.5),
          max.words=100,
          random.order=FALSE,
          rot.per=0.3,
          colors=brewer.pal(8, "Dark2"))

enter image description here