[R] adjust space between horizontal legend text in a barplot

arun smartpink111 at yahoo.com
Wed Jun 13 06:42:40 CEST 2012


Hi,

Sorry about that.  My mistake.


Try this:
 barplot(VADeaths, names=rep("", 4), col=gray(1:3/4+0.01)) 

legend("bottom", legend=expression(scriptstyle("Strongly disagree/disagree"),scriptstyle("Neutral"),scriptstyle("Strongly agree/agree")), fill=gray(1:3/4+0.01), inset=-0.2, bty='n', horiz=T, x.intersp=0.5,xjust=0,yjust=0,text.width=c(1,0.25,1))

#You can change the text.width value to increase or decrease the spacings.

A.K.


________________________________
From: Jianyun Wu <jianyun.fred.wu at gmail.com>
To: arun <smartpink111 at yahoo.com> 
Cc: R help <r-help at r-project.org> 
Sent: Tuesday, June 12, 2012 11:57 PM
Subject: Re: [R] adjust space between horizontal legend text in a barplot


Thanks for the reply. 
The one you provide is the vertical legend not for horizontal legend. 
x.intersp=  simply spreads out the space between symbols and legend text. 

using the existing data in R for example, 
barplot(VADeaths, names=rep("", 4), col=gray(1:3/4+0.01)) #five levels in this data, but just for example purpose
legend <- c("Strongly disagree/disagree", "Neutral", "Strongly agree/agree")
par(xpd = TRUE) 
legend("bottom", legend=legend, fill=gray(1:3/4+0.01), inset=-0.2, bty='n', horiz=T, x.intersp=0.5) 


On Wed, Jun 13, 2012 at 1:27 PM, arun <smartpink111 at yahoo.com> wrote:

Hi,
>Try this.
>
>  plot(0)
>  legend("topright", inset=c(0.2,0),legend=c("Strongly disagree/disagree","Neutral","Strongly agree/agree"), lty=1:3, pch=1:3, x.intersp=2)
>
>A.K.
>
>
>
>
>----- Original Message -----
>From: Jianyun Wu <jianyun.fred.wu at gmail.com>
>To: r-help at r-project.org
>Cc:
>Sent: Tuesday, June 12, 2012 10:45 PM
>Subject: [R] adjust space between horizontal legend text in a barplot
>
>Hi All,
>
>I produced a barplot and made a horizontal legend below the graph.
>Because the results are from a survey, there are three levels, namely
>strongly disagree/disagree, neutral and strongly agree/agree.
>
>
>> rownames(survey)[1] "Strongly disagree/disagree" "Neutral"                    "Strongly agree/agree"
>
>
>
>As in the output above, there is a large space between "Neutral" and
>"Strongly agree/agree".
>
>This large space appears in the horizontal legend as well.
>
>
>
>So is there anyway I can reduce such a large gap in the legend when it
>is superimposed horizontally?
>
>
>
>Thanks and Regards
>
>
>
>Fred
>
>    [[alternative HTML version deleted]]
>
>______________________________________________
>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.
>
> 



More information about the R-help mailing list