R的plot 既可以绘制点,也可以绘制直方图,还可以绘制箱线图,感觉的确很智能。
> 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 b 1 1.0 1.00 2 1.5 1.25 3 2.0 1.50 4 2.5 1.75 5 3.0 2.00 6 3.5 2.25 7 4.0 2.50 > barplot(as.matrix(r), col=rainbow(9))
另外发现一个绘制热图的 function
# ----- 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 values if( is.null(xLabels) ){ xLabels <- c(1:ncol(x)) } if( is.null(yLabels) ){ yLabels <- c(1:nrow(x)) } layout(matrix(data=c(1,2), nrow=1, ncol=2), widths=c(4,1), heights=c(1,1)) # 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 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
本文出自 “R和Python应用” 博客,请务必保留此出处http://matrix6ro.blog.51cto.com/1746429/1892672
原文地址:http://matrix6ro.blog.51cto.com/1746429/1892672