Branches of mechanical engineering: Using Wordcloud On Search Damage & Phrases



https://www.r-bloggers.com/using-wordcloud-on-search-terms-phrases/


The wordcloud packet for R is great, only all the examples I establish used the tm packet to procedure a large sum of textual information (web pages, text files, google docs, etc.)
But what if y'all accept normalized information where y'all accept a give-and-take as well as its frequency? Or, what if y'all accept phrases that y'all desire inward a wordcloud? One instance beingness damage which users accept entered into a spider web search.
I tumble out to endure pulling from a information origin via PHP as well as and therefore I output the information to CSV format inward descending social club past times frequency.

The relevant business office of the PHP script (after populating the array $terms):

$cwd = getcwd();
$local_path = $cwd.’/csv/’;
$filename = $local_path.’searchterms.csv’;
$fp = fopen($filename, ‘w’);
fputcsv($fp, array(‘term’,’freq’));
arsort($terms); //reverse form array past times values
$max_terms = 100;
$i = 0;
foreach ($terms equally $q => $v) {
    $i++;
    if ($v > $min_freq) fputcsv($fp, array($q,$v));
    if ($i > $max_terms) break;
}
fclose($fp);

Here is the sample data:

term,freq
“target dark friday”,8239
“walmart layaway”,6502
“america idol”,1777
“american idol episodes”,1741
“mexican develop domino game”,1585
“jc penny outlet store”,1159
“the chicago code”,1130

The R script:

require(wordcloud)
require(RColorBrewer)
datain <- read.csv(“csv/searchterms.csv”, colClasses=c(“character”, “numeric”))
pal2 <- brewer.pal(8,”Dark2″)
png(“wordcloud.png”, width=1000,height=1000)
wordcloud(datain$term,datain$freq, scale=c(8,.4),min.freq=1, max.words=Inf, random.order=FALSE, rot.per=.15, colors=pal2)
dev.off()
One consideration is that if a search phrase is likewise long, R volition create a alert as well as omit it from the resulting wordcloud, therefore y'all bespeak to compensate amongst the ikon dimensions. It may endure possible to dynamically scale the ikon based on the string length of the highest frequency result.

Here is the resulting wordcloud:

For to a greater extent than on R, visit https://www.r-bloggers.com/

Sumber http://engdashboard.blogspot.com/

Jangan sampai ketinggalan postingan-postingan terbaik dari Branches of mechanical engineering: Using Wordcloud On Search Damage & Phrases. Berlangganan melalui email sekarang juga:

Bali Attractions

BACA JUGA LAINNYA:

Bali Attractions