Hi, I'm wondering how can I change the position of xlab in truehist. For example, the following code creats a histogram with 4 bins for my discrete data. I want each bin to be labelled as 0, 1, 2, or 3 in the middle, so that it's clear each bin corresponds to each of the discrete case. I was thinking of first delete xlab and then add marks myself, but it doesn't look like it's working. The old label can not be removed by setting xlab="" or xlab = NULL. Thanks for your help! Hua #------------------------ x = c(rep(0,10),rep(1,100),rep(2,50), rep(3,30)) library(MASS) truehist(x,nbins=4) truehist(x,nbins=4,xlab="")
On Apr 16, 2010, at 6:00 PM, Hua Li wrote:> Hi, > > I'm wondering how can I change the position of xlab in truehist. > For example, the following code creats a histogram with 4 bins for > my discrete data. I want each bin to be labelled as 0, 1, 2, or 3 in > the middle, so that it's clear each bin corresponds to each of the > discrete case. > > I was thinking of first delete xlab and then add marks myself, but > it doesn't look like it's working. The old label can not be removed > by setting xlab="" or xlab = NULL.xlab is the annotation for the whole axis... just one string with the name of the vector unless you offer an alternative... nothing to to with lableing the ticks. You want to look at the axis funtion and the at= and labels= arguments. See example at bottom of plot.default page.> > Thanks for your help! > > Hua > > #------------------------ > x = c(rep(0,10),rep(1,100),rep(2,50), rep(3,30)) > library(MASS) > truehist(x,nbins=4) > > truehist(x,nbins=4,xlab="") > > ______________________________________________ > 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.David Winsemius, MD West Hartford, CT
On 2010-04-16 16:00, Hua Li wrote:> Hi, > > I'm wondering how can I change the position of xlab in truehist. For example, the following code creats a histogram with 4 bins for my discrete data. I want each bin to be labelled as 0, 1, 2, or 3 in the middle, so that it's clear each bin corresponds to each of the discrete case. > > I was thinking of first delete xlab and then add marks myself, but it doesn't look like it's working. The old label can not be removed by setting xlab="" or xlab = NULL. > > Thanks for your help! > > Hua > > #------------------------ > x = c(rep(0,10),rep(1,100),rep(2,50), rep(3,30)) > library(MASS) > truehist(x,nbins=4) > > truehist(x,nbins=4,xlab="")I think you misunderstand 'xlab'; it's the label for the x-axis, i.e. the 'x' that is produced by your first truehist() call. You want to change the value labels on the axis. You're on the right track by leaving that off and then adding your preferred labels at your preferred locations: truehist(x, nbins = 4, xaxt = "n") ## see xaxt under ?par axis(1, at = 0:3 + 0.5, labels = 0:3) I usually add box(bty = "l") -- Peter Ehlers University of Calgary