[R] barplot: width of label

David Winsemius dwinsemius at comcast.net
Sun Dec 19 17:18:25 CET 2010


On Dec 19, 2010, at 10:55 AM, Peter Ehlers wrote:

> On 2010-12-19 07:13, fransiepansiekevertje wrote:
>> Hello,
>> I try to make barplots with rather wide labels. A simplified  
>> example of
>> this:
>>
>> x<- c(12, 33, 56, 67, 15, 66)
>> names(x)<- c('Richard with a long surname','Minnie with a long
>> name,'Albert','Helen','Joe','Kingston')
        ^
>> barplot(x, las = 2)

Anyone pasting this code should insert the missing single-quote.
>>
>> Now the label 'Richard with a long surname' is too long to fit  
>> beneath the
>> bars. A simple solution would be enlarge the space for the labels by
>> positioning the bar region higher. But I cannot find how to do  
>> this. Please
>> Help!
>>
>
> Try
>
> par(mar = c(12,4,4,2))
>
> before calling barplot(). But a better solution (still requiring a
> resetting of the default margins) would be to plot horizontally.
> Admittedly, this would provide less neck exercise for the reader.

Another option is to insert \n's.

x <- c(12, 33, 56, 67, 15, 66)
names(x) <- c('Richard\n with a\n long \nsurname','Minnie\nwith a 
\nlong \n name','Albert','Helen','Joe','Kingston')
  barplot(x)
And yet another option, somewhat more complex, would be to construct  
an x- axis with slanting labels. (Several worked examples posting in  
the archives.)

-- 
David


>
> Peter Ehlers
>
>> Frans Marcelissen, DigiPsy
>> fransiepansiekevertje at digipsy.nl
>>
>> ______________________________________________
>> 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.
>
> ______________________________________________
> 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



More information about the R-help mailing list