Basic Drawing Package-plot function of R

Source: Internet
Author: User

R's plot can draw points, can also draw histograms, and can draw the box plot, it is really smart.

> B <-C ("P", "P", "P", "Q", "Q", "Q") > C <-C ("TQ", "AQ", "CQ", "BQ", "XQ", "XQ") > A <-C ("A", "B", "C", "D", " E "," F ") > Ct <-C (6,7,3,6,1,9) > CA <-data.frame (a,b,c, CT) > Plot (ca$a, ca$b, yaxt=" n ", Axes=f) > Plot (ca$ B, Ca$c, yaxt= "n", Axes=f) > Plot (ca$b, ca$ct, yaxt= "n") > Plot (ca$a, ca$ct, yaxt= "n") > R a B1 1.0 1.002 1.5 1.253 2.0 1.504 2.5 1.755 3.0 2.006 3.5 2.257 4.0 2.50> Barplot (As.matrix (R), Col=rainbow (9))



Also found a function to draw a heat map

# ----- Define a function for plotting a matrix ----- # Myimageplot <- function (x,  ...) {     min <- min (x)      max <- max (x)      ylabels <- rownames (x)      xlabels  <- colnames (x)      title <-c ()   # check for  additional function arguments  if ( length (List (...))  ) {    lst <- list (...)     if ( !is.null (lst$zlim)  ) {       min  <- Lst$zlim[1]       max <- Lst$zlim[2]     }    if ( !is.null (lst$ylabels)  ) {        ylabels <- c (lst$ylabels)      }    if ( !is.null (lst$xlabels)  ) {        xlabels <- c (lst$xlabels)     }    if (  !is.null (lst$title)  ) {       title <- lst$title     }  }# check for null valuesif ( is.null (xLabels)  ) {   xlabels <- c (1:ncol (x))}if ( is.null (ylabels)  ) {    ylabels <- c (1:nrow (x))}layout (Matrix (data=c),  nrow=1, ncol=2),  widths=c (4,1),  heights=c ()  # red and green range from 0 to 1  while blue ranges from 1 to 0 colorramp <- rgb ( seq (0,1,length=256),  # red                     seq (0,1,length=256),  # green                    seq (1,0,length=256))   # Blue  colorlevels <- seq (Min, max, length=length (colorramp))  # Reverse Y  axis reverse <- nrow (x)  : 1 ylabels <- ylabels[reverse]  x <- x[reverse,] # data map par (Mar = c (3,5,2.5,2))   Image (1:length (xlabels),  1:length (Ylabels),  t (x),  col=colorramp, xlab= "",  ylab= "",  axes=false, zlim=c (Min,max))  if ( !is.null (title)  ) {    title ( Main=title)  }axis (Below<-1, at=1:length (xlabels),  labels=xlabels, cex.axis=0.7)   Axis (Left <-2, at=1:length (ylabels), labels=ylabels, las= horizontal<-1,  cex.axis=0.7)  # color&nbsp Scale par (Mar = c (3,2.5,2.5,2))  image (1, colorlevels,       matrix (Data=colorlevels, ncol=length (colorlevels), nrow=1),       col= Colorramp,      xlab= "", ylab= "",       xaxt= "n")  layout (1)}# ----- END plot function ----- #


Ref:http://www.phaget4.org/r/image_matrix.html

This article is from the "R and Python apps" blog, so be sure to keep this source http://matrix6ro.blog.51cto.com/1746429/1892672

Basic Drawing Package-plot function of R

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.