R language combined with rcolorbrewer color extension package to draw landscape histogram

Source: Internet
Author: User
Tags rcolorbrewer


first load the color expansion pack rcolorbrewer, the specific use of color packs can be found in this article http://book.2cto.com/201408/45552.html

Library (Rcolorbrewer)

This article takes the output of the Hadoop cluster WordCount program as the data source

650) this.width=650; "title=" QQ picture 20150429184211.png "alt=" wkiol1vatyijfn9faacqsdjbw8u746.jpg "src="/http S3.51cto.com/wyfs02/m02/6c/23/wkiol1vatyijfn9faacqsdjbw8u746.jpg "/>

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,REPL ACE=F),] #随机抽样或者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% '))

650) this.width=650; "title=" QQ picture 20150429191528.png "alt=" wkiol1vavs7qd_5yaaejl5uhkvo876.jpg "src="/http S3.51cto.com/wyfs02/m01/6c/23/wkiol1vavs7qd_5yaaejl5uhkvo876.jpg "/>


You can refer to this article for reference

Http://book.2cto.com/201408/45574.html






This article is from "Skywalker, in the Cloud" blog, please be sure to keep this source http://tianxingzhe.blog.51cto.com/3390077/1640452

R language combined with rcolorbrewer color extension package to draw landscape histogram

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.