R Language for horizontal column drawing

Source: Internet
Author: User


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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.