[R] histogam plots
Bill.Venables at csiro.au
Bill.Venables at csiro.au
Thu Feb 11 06:15:17 CET 2010
One way round this is to use lattice. With your matrix 'w' you might
W <- data.frame(w = as.vector(w),
r = factor(as.vector(row(w))) )
require(lattice)
histogram(~w|r, W)
Identical axis systems will be used for all panels.
Bill Venables
CSIRO/CMIS Cleveland Laboratories
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of li li
Sent: Thursday, 11 February 2010 2:52 PM
To: r-help
Subject: [R] histogam plots
Hi all,
I want to draw a histgram for each row of a matrix and compare them.
However the plot I
got does not have the same y range and x range, which makes it difficult to
make the comparison.
Is there a easy way to fix the x range and y range in a xy plot for several
plots, instead of specifying
them for each plot.
The following is my code for generalizing the matrix and draw the
histogram.
############gen is the function to generate the dta
gen <- function(m, rho) {
library(MASS)
set.seed(103)
theta <- 0
theta1 <- 2
pi0 <- 0.9
mzero <- pi0*m
mean <- c(rep(theta, mzero), rep(theta1,m-mzero))
J <- rep(1, m)
var <- function(rho) {(1-rho)*diag(m)+ rho*J%*%t(J)}
t <- mvrnorm(1, mean, var(rho))
return(t)
}
####### w is the matrix. A histgram is drawn for each of the rows.
n <- 1000
r <- seq(0,0.9, by=0.1)
w <- matrix(0, ncol=n, nrow=length(r))
for (i in 1: length(r)){w[i,]<- gen(n,r[i])}
par(mfrow=c(2,5))
hist(w[1,], breaks=100)
hist(w[2,], breaks=100)
hist(w[3,], breaks=100)
hist(w[4,], breaks=100)
hist(w[5,], breaks=100)
hist(w[6,], breaks=100)
hist(w[7,], breaks=100)
hist(w[8,], breaks=100)
hist(w[9,], breaks=100)
hist(w[10,], breaks=100)
##############################
Thank you !
Li
[[alternative HTML version deleted]]
______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list