Thanks Marc & Liaw!

On 3/15/06, Marc Schwartz (via MN) <mschwartz@mn.rr.com> wrote:
>
> On Wed, 2006-03-15 at 17:54 +0100, jia ding wrote:
> > Hi,
> >
> > I have a file named:
> > test_R.txt
> > aaa  2
> > bbb  5
> > ccc  7
> > sss  3
> > xxx  8
> >
> > I want to have a plot:
> > test<-read.table("test_R.txt",col.name=c("Name","Score"))
>
> > par(mfrow=c(1,2))
>
> It's not clear what the purpose is here, at least in this example. Do
> you plan on creating a second plot?


Yes, I want to plot the second one.
e.g. the second file is :
test2_R.txt
zszs  2
gjie  4
gjai  5
opwn  6
jgio  3
gjwn  8
owln  6
aonl  1
gols  7

I post the complete command here:

test<-read.table("/vol/fpsearch/jiading/berman/single/test_R.txt",col.name=c
("Name","Score"))
#single<-single[order(-single$Weights),]   
#decreastest_R.txt",col.name=c("Name","Score"))

test2<-read.table("/vol/fpsearch/jiading/berman/single/test2_R.txt",
col.name=c("Name","Score"))
par(mfrow=c(2,1))
t<-barplot(test$Score,space=0.5)
axis(1,at=t,labels=as.character (test$Name))
t2<-barplot(test2$Score,space=0.5)
axis(1,at=t2,labels=as.character(test2$Name))

P1; The problem is, even I set each plot with "space=0.5", the bar's width
are different. The first plot's bars are lot wider than the second plot's.
What I want is, to make 2 plots same width.

> barplot(test$Score)
> > name<-test$Name
> > axis(1,at=1:length(test$Name),labels=paste(name))
> >
> > Q1, if you try the script above,you will get 5 bars, the axis only shows
> > "aaa", "ccc","xxx", but where are "bbb"&"sss"?
>
> The easiest way to do this is to use the ' names.arg' argument in
> barplot():
>
> barplot(test$Score, names.arg = as.character(test$Name))


P2:  if I made 2 barplot next to each other by: par(mfrow=c(1,2)).  It seems
" names.arg" doesn't work for the second plot ( test2_R.txt), as it
automatically hides some of the labels. Of course, in order to draw
everything, I can try to rotate the labels e.g. par(las=2).  While, I am
thinking, it should have some solution to solve this problem without turning
labels.

P3: if I typed pdf("test.pdf")
Suppose the plot has lots of bars.  Sometimes,there is not enough space for
pdf to draw everything. Which means it's not a complete file. Do you have
any suggestion about it?

PS: do you know, if there is the website which provides all the questions
people are asking now?  I mean,  when I  have problems I send email to
r-help@stat.math.ethz.ch, and then some nice people will have a look of my
problems and send me back their solutions. I am puzzled, except daily
R-help-request mail, how can I get other people's r-help mail simultaneous?
I remember I do subscribe to the mail group.

Thanks!

Nina



Note that the 'Name' column in the 'test' data frame will be a factor by
> default, so you need to convert it to a character vector here.
>
> > Q2, pls have a look this x-axis again, you will find the middle of the
> bars
> > are not pointing to the x-axes.
>
> Note that in the Value section of ?barplot, it indicates that barplot()
> returns the bar midpoints, which are not at integer values along the x
> axis.
>
> You would need to do something like:
>
> mp <- barplot(test$Score)
>
> axis(1, at = mp, labels = as.character(test$Name))
>
>
> > Q3, how can i change the width of the bars? I feel they are too "fat".
>
> You can use the 'space' argument:
>
> barplot(test$Score, names.arg = as.character(test$Name), space = 0.5)
>
>
> See the descriptions of the 'width' and 'space' arguments in ?barplot
> for some of the subtleties here.
>
> See ?barplot for more information and further examples.
>
> HTH,
>
> Marc Schwartz
>
>
>

	[[alternative HTML version deleted]]


