[R] histogram

Jim Lemon jim at bitwrit.com.au
Wed Oct 14 09:31:20 CEST 2009


On 10/13/2009 10:06 PM, Dmitry Gospodaryov wrote:
> Dear R developers,How I can build a histogram from matrix:
>
> 0 0.5 1
>
> 0.25 34 43 65
> 1 23 35 54
> 4 22 29 42
> 10 21 22 29
> 20 15 17 20
>
> (first string is represented names of columns,
> first column is represented names of rows)
> where names of columns should be x-axis labels; respectively
> to this, I want to have three groups of bars (5 bars in each group)?
> Y values should be represented by values given in the "core" of
> matrix. Names of the rows should be in a legend, and should
> represent the each of 5 bars (in group) name.

dgd<-read.table("dg.dat",header=TRUE)
names(dgd)<-c("blank","0","0.5","1")
library(plotrix)
barp(dgd[,2:4],names.arg=names(dgd)[2:4],col=2:6)
legend(1,65,dgd[,1],fill=2:6)

> I would also try to build filled contour, however, i can't
> "ask" the program to consider column and rownames like
> true values, not only like labels. So, column names should
> be the y-values, while row names should be the x-values.
> Values placed in the "core" of matrix should be z-values.
>
filled.contour(dgd[,1],as.numeric(names(dgd)[2:4]),
  as.matrix(dgd[,2:4]))

Jim




More information about the R-help mailing list