R language and Data Analysis II: Drawing

Source: Internet
Author: User
Tags air1

Graphic display is the most efficient and image of the data description means, so the smart image display is a high-quality data analysis report of the necessary content, so the powerful graphical display function is also a statistical analysis software necessary features. The R language provides a powerful display of vomiting blood. Today I'm going to share with my small partners how to draw the graphics you want with the R language from simple to complex.

Let's start by listing all the available graphics:

1, Histogram (hist ()), 2, Scatter chart (plot ()), 3, Histogram (Barplot ()), 4, pie chart (Pie ()), 5, Box Line (BoxPlot ()), 6, astrological chart (stars ()), 7, Facebook (Faces ()), 8, Stem and leaf diagram ( Stem ()); 9, QQ Chart (Qqnorm ()); 10, Map package maps, MapData, Geosphere

To facilitate graphical presentation, we create a data scenario, assuming we need to count the student's 3-course exam. We generated the study number, the higher mathematics (80 to 100 uniform distribution), the linear algebra (mean 80, the standard deviation of 7 normal distribution) and the operations Research (mean 83, standard deviation 18 normal distribution) three results. The corresponding statement is:

Num=seq (102001,102100) x1=round (runif (100,min=80,max=100)) X2=round (Rnorm (100,mean=80,sd=7)) X3=round (Rnorm (100, MEAN=83,SD=18))

Basic statistics-Single indicator

Considering that all results cannot exceed 100 points, it is necessary to change the randomly generated scores above 100 points to 100 points and to save the final corrected scores with the student number in the data frame.

X2[which (x2>100)]=100x3[which (x3>100)]=100x=data.frame (NUM,X1,X2,X3)

Draw the histogram of higher mathematics results, scatter plot of the correlation relation between higher mathematics and linear algebra, the histogram of operational research results and pie chart, to see the distribution of the results of each section. The corresponding statements are as follows:

hist (x$x1) plot (x1,x2) Barplot (table (x$x1)) Pie (table (x$x1))

Basic statistics-Multi-indicators

Then we will be three of the results with two kinds of box-line drawing out, box-line diagram can be more clearly explained the distribution of data, and the concentration of data areas. The command is as follows:

BoxPlot (x$x1, x$x2, x$x3) BoxPlot (X[2:4],col=c ("Red", "green", "Blue"), notch=t)

To make it easier to observe the characteristics of individual units, R provides an astrological chart, a facial image (reflecting data based on the shape of the face and the size of the eye) to reveal the differences in each individual's attributes, as follows:

Stars (X[c ("X1", "X2", "X3")]) install.packages ("Teachingdemos") Library ("Teachingdemos") Faces2 (X)

In visualizing the data, R also provides stem and leaf control of our view data distribution, the command is as follows:

Stem (x$x2)

The R language also provides a figure showing whether the sequence is subject to normal distribution, can be easily judged by the naked eye, when the scattered points of the distribution closer to the straight line, the distribution of the sequence is closer to normal distribution. The command is as follows:

Qqnorm (X3) qqline (X3)

Map column

Finally, we introduce the rich map package features provided by R language, first we need to install the maps package, can be used to draw a beautiful map of the world for us to do social network analysis. Unfortunately, the package does not contain China map package, if need to draw a map of China, in terms of suggestions to load MapData package, on the other hand, strongly recommend Google contribute to the Ggmap package, the relevant commands are as follows:

Library (Maps) map ("World", Fill=true,col=rainbow, Ylim=c ( -60,90), Mar=c (0,0,0,0))

Library (mapdata) map ("China", col= "Red4", Ylim=c (18,54), Panel.first=grid ())

Finally, an airline route distribution case, the end of today's R language mapping introduction, first I first import external data, and then construct the route, the final display in the graph. The command is as follows:

Airports <-read.csv ("Http://datasets.flowingdata.com/tuts/maparcs/airports.csv", header=true) flights <- Read.csv ("Http://datasets.flowingdata.com/tuts/maparcs/flights.csv", Header=true, As.is=true) map ("World", col= "# F2f2f2 ", fill=true,bg=" white ", lwd=0.5) fsub <-flights[flights$airline==" AA ",]for (J in 1:length (Fsub$airline)) { Air1 <-Airports[airports$iata = = fsub[j,] $airport 1,]air2 <-airports[airports$iata = = fsub[j,] $airport 2,]inter & lt;-Gcintermediate (C (air1[1,] $long, air1[1,] $lat), C (Air2[1,] $long, air2[1,] $lat), n=100, addstartend=true) lines ( Inter, col= "black", lwd=0.8)}

At this point about the R language of the drawing of the end of the content, I hope to all of you friends help

R language and Data Analysis II: Drawing

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.