Rex C. Eastbourne
2010-Jan-15 20:01 UTC
[R] Possible to write text inside a bar of a barplot?
How can I write text inside a bar of a barplot? I tried using text(), but I am only able to specify the numeric y-coordinate. The different columns of my barplot correspond to factors and not numbers, so I don't know how to access the horizontal positions of the bars. I tried fiddling with different values of the "adj" argument, but this appears unreliable. Background: I have created a barplot visualization where the bars represent the size of different items (e.g. US state populations), and the sub-bars represent the size of the different sub-components of each item (e.g. counties). Picture: http://drop.io/hjcodjj/asset/capture-png I would like to put in a label inside each sub-bar (e.g. indicating the name of the county represented by that sub-bar). Rex p.s.: In case anyone finds this visualization useful I'll share my code afterward, but just need to get the labeling working properly first. [[alternative HTML version deleted]]
Rex C. Eastbourne
2010-Jan-15 20:54 UTC
[R] Possible to write text inside a bar of a barplot?
Thanks for the replies! The answer is that barplot() returns the x coordinates of the bars. On Fri, Jan 15, 2010 at 12:01 PM, Rex C. Eastbourne < rex.eastbourne@gmail.com> wrote:> How can I write text inside a bar of a barplot? I tried using text(), but I > am only able to specify the numeric y-coordinate. The different columns of > my barplot correspond to factors and not numbers, so I don't know how to > access the horizontal positions of the bars. I tried fiddling with different > values of the "adj" argument, but this appears unreliable. > > Background: I have created a barplot visualization where the bars represent > the size of different items (e.g. US state populations), and the sub-bars > represent the size of the different sub-components of each item (e.g. > counties). Picture: http://drop.io/hjcodjj/asset/capture-png > > I would like to put in a label inside each sub-bar (e.g. indicating the > name of the county represented by that sub-bar). > > Rex > > p.s.: In case anyone finds this visualization useful I'll share my code > afterward, but just need to get the labeling working properly first. >[[alternative HTML version deleted]]