Re: [R] Question about 'lables' ect.
Thanks Marc Liaw! On 3/15/06, Marc Schwartz (via MN) [EMAIL PROTECTED] 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 bbbsss? 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]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Question about 'lables' ect.
On Thu, 2006-03-16 at 10:37 +0100, jia ding wrote: Thanks Marc Liaw! On 3/15/06, Marc Schwartz (via MN) [EMAIL PROTECTED] 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. The problem of course is that you have a different number of bars in each plot. Note from ?barplot: space: the amount of space (as a fraction of the average bar width) left before each bar. While the average bar width in each plot is 1, this is a measure based upon 1 unit on the x axis range. Since both plots are being drawn in the same horizontal dimension, but have differing x axis ranges, a 1 in the first plot is larger than a 1 in the second plot. One possible workaround is to set the x axis ranges to the same value: par(mfrow=c(2, 1)) t - barplot(test$Score, space = 0.5, xlim = c(0, 14)) axis(1, at = t,labels = as.character(test$Name)) t2 - barplot(test2$Score,space = 0.5, xlim = c(0, 14)) axis(1, at = t2,labels = as.character(test2$Name)) The possible downside of this approach is that it puts the bars in the first plot offset to the left, with the remainder of the x axis space unused. Alternatively, you can increase the size of 'space' in the first plot to reduce the width of the bars until the widths are comparable: par(mfrow=c(2, 1)) t - barplot(test$Score, space = 1.75) 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)) It just depends upon the look that you want and what aids in reader interpretation. 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 bbbsss? 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. The problem is that there is not enough horizontal space for the labels. If you drag the size of the plot window horizontally, they should show as you provide more physical space in the plot device for them. Alternatively, if you set 'cex.axis' in the calls to axis() as below, they will be small, but will be there. par(mfrow=c(1,2)) t - barplot(test$Score, space = 0.5) axis(1, at = t,labels = as.character(test$Name), cex.axis = 0.1) t2 - barplot(test2$Score,space = 0.5) axis(1, at = t2,labels = as.character(test2$Name), cex.axis = 0.1) Of course, you can make them small enough that they are hard to read. Thus, rotating the labels may not be a bad idea if this is the layout you want. 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? Did you remember to call: dev.off() after all plot related calls are complete to close the PDF file? If you don't, then the output of the final plot function related calls do not get flushed to the file and you end up with an incomplete graph. 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] Question about 'lables' ect.
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)) 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 bbbsss? Q2, pls have a look this x-axis again, you will find the middle of the bars are not pointing to the x-axes. Q3, how can i change the width of the bars? I feel they are too fat. Thanks! Nina [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Question about 'lables' ect.
Try something like: xp - barplot(test$Score, space=.5) axis(1, at=xp, labels=as.character(test$Name)) See ?barplot more more detail. Andy From: jia ding 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)) 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 bbbsss? Q2, pls have a look this x-axis again, you will find the middle of the bars are not pointing to the x-axes. Q3, how can i change the width of the bars? I feel they are too fat. Thanks! Nina [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Question about 'lables' ect.
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? 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 bbbsss? The easiest way to do this is to use the 'names.arg' argument in barplot(): barplot(test$Score, names.arg = as.character(test$Name)) 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 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html