To first load the color extension pack rcolorbrewer, see the following two articles for specific use http://book.2cto.com/201408/45552.html,http:// tianxingzhe.blog.51cto.com/3390077/1641199
Library (Rcolorbrewer)
This article takes the output of the Hadoop cluster WordCount program as the data source
The collation code of the data is as follows
X=read.delim ("C:/users/a/desktop/sample.txt", Header=false) #读入文本数据
names (x) =c ("word", "count") #加表头
x= Transform (x, Pct=round (X$count/sum (x$count) *100)) #数据框增加百分比列
Y=x[order (x[,2],decreasing=t),] #排序
z=x[sample (Nrow (x), 20,replace=f),] #随机抽样
or Z=head (y,n=11), tail (y,n=11) #抽取前后11行, this example uses a random sampling
To draw a horizontal histogram, detailed command parameter interpretation can be found in the following blog http://blog.csdn.net/rav009/article/details/40149405
The code is as follows:
Barplot (rev (z$pct), Horiz=t,xlim=c ( -4,5), Axes=f,col=brewer.pal (one, "BRBG") [1:11])
text (seq (from=0.7, length.out=20,by=1.2), X=-0.5,label=rev (Z$word))
axis (3,c (0,1,2,3,4,5), C (' 0% ', ' 10% ', ' 20% ', ' 30% ', ' 40% ', ' 50% ') ))
You can refer to this article for reference
Http://book.2cto.com/201408/45574.html
This article is from the "bit accumulation" blog, please be sure to keep this source http://tianxingzhe.blog.51cto.com/3390077/1640452