[R] working with groups of labels?

Jim Lemon jim at bitwrit.com.au
Tue May 12 12:11:02 CEST 2009


Phillip Porter wrote:
> At 9:25 PM +1000 5/11/09, Jim Lemon wrote:
>> Hi Phillip,
>> I'm not exactly sure how you are positioning the labels. Is it 
>> possible to give us an example with some data that will produce a 
>> plot to show what you want? It shouldn't be too hard to do.
>> Jim
>
>
> Data is something along the lines of:
>
> variable                score
> Real Bad Stuff  0
>        Real    23
>       Bad     14
>       Stuff   17
> Other Crazy Things      0
>         Other   18
>       Crazy   43
>         Things  13
>
> The basic plot looks like this:
>
> barplot(score, horiz=TRUE, axes=FALSE, las=2, space=1, 
> names.arg=c("Real Bad Stuff", "Real","Bad","Stuff","Other Crazy 
> Things","Other","Crazy","Things"))
>
>
> I've been trying make it look the way I want it by doing this:
>
> barplot(score, horiz=TRUE, axes=FALSE, las=1, space=1, names.arg=c("", 
> "Real","Bad","Stuff","","Other","Crazy","Things"), cex.names=.5)
> mtext(c("Real Bad Stuff","Other Crazy Things"),at=c(8,15.6),side=2, 
> line=1.5,adj=1, las=1, cex=.5, font=2)
>
> The mtext is annoying to line up with the actual plot.  If there was a 
> way to get it to line up with the variables that would solve my 
> problems, but I've tried at=variable and at=score (putting in "" for 
> all of the variable names I don't want bolded and left justified) and 
> neither way gets them to line up.
>
> Thanks,
> Phillip
Hi Phillip,
Try this:

pporter<-read.csv("pporter.csv")
pporter
            variable score
1     Real Bad Stuff     0
2               Real    23
3                Bad    14
4              Stuff    17
5 Other Crazy Things     0
6              Other    18
7              Crazy    43
8             Things    13
par(mar=c(5,8,4,2))
barpos<-barplot(pporter$score, horiz=TRUE, axes=FALSE, las=1, space=1,
 names.arg=c("", "Real","Bad","Stuff","","Other","Crazy","Things"),
 cex.names=.5)
mtext(c("Real Bad Stuff","Other Crazy Things"),at=barpos[c(1,5)],
 side=2, line=5,adj=0, las=1, cex=.5, font=2)

Jim




More information about the R-help mailing list