[R] axis placement with stacked barplots and the asp=1 parameter

2005-01-21 Thread Kavithan Siva
Hi,

I'm currently using barplot to generate vertically stacked bar charts.
I'd like to be able to use the asp=1 parameter with barplot(), but
doing this causes the y axis to be placed on the far left as shown in
the attachment demo.pdf.

I could get around this by using the negative values for the line
parameter of the axis() function. I'd rather not do this and imagine I'm
doing something wrong. Any help would be much appreciated.

Thanks
Kav
 
 ---
This e-mail may contain confidential and/or privileged information. If you are 
not the 
intended recipient (or have received this e-mail in error) please notify the 
sender 
immediately and destroy this e-mail. Any unauthorised copying, disclosure or 
distribution 
of the material in this e-mail is strictly forbidden. The Prytania Group has 
taken every 
reasonable precaution to ensure that any attachment to this e-mail has been 
swept for 
viruses. However, we cannot accept liability for any damage sustained as a 
result of 
software viruses and would advise that you carry out your own virus checks 
before 
opening any attachment.
__
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] axis placement with stacked barplots and the asp=1 parameter

2005-01-21 Thread Uwe Ligges
Kavithan Siva wrote:
Hi,
I'm currently using barplot to generate vertically stacked bar charts.
I'd like to be able to use the asp=1 parameter with barplot(), but
doing this causes the y axis to be placed on the far left as shown in
the attachment demo.pdf.
See the posting guide, some file types (including pdf) will be omitted 
from your messages to R-help. You might want to specify a short but 
easily reproducible examples in 2-5 lines of code.

Why do you want to use asp with a barplot???
Uwe Ligges

I could get around this by using the negative values for the line
parameter of the axis() function. I'd rather not do this and imagine I'm
doing something wrong. Any help would be much appreciated.
Thanks
Kav
 
 ---
This e-mail may contain confidential and/or privileged inf...{{dropped}}
__
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] axis placement with stacked barplots and the asp=1 parameter

2005-01-21 Thread Marc Schwartz
On Fri, 2005-01-21 at 12:09 +, Kavithan Siva wrote:
 Hi
 
 Here's some example code which illustrates the issue:
 
 dataSeries-array(0, c(5, 2))
 
 dataSeries[1, 1] - 5
 dataSeries[2, 1] - 5
 dataSeries[3, 1] - 0
 dataSeries[4, 1] - 2
 dataSeries[5, 1] - 0
 
 dataSeries[1, 2] - 7
 dataSeries[2, 2] - 0
 dataSeries[3, 2] - 0
 dataSeries[4, 2] - 0
 dataSeries[5, 2] - 1
 
 barplot(dataSeries, asp=1)
 
 Removing the asp=1 parameter produces a correct looking plot. I need to
 use the asp=1 parameter because I was re-writing the barplot function to
 create stacked charts with rounded corners (instead of rectangles). For
 the arc at the corners of the bars to look correct I need asp=1. I've
 attached a .ps file to show you what I was trying to achieve.
 
 Thanks
 Kav

There are a couple of options to consider here. First, note that using
the 'asp' argument forces the x and y axes to be scaled such that one
unit of measurement in each direction is the same. As you are seeing,
this impacts the look of curves and of course would be relevant to
certain plots where the horizontal and vertical measures need to be
square.

One option is to leave the plot as is, but move the y axis closer to
the bars. Using your same data above:

# Draw the plot, but no axes
barplot(dataSeries, asp=1, axes= FALSE)

# Now using the 'line' argument, move the axis closer
# to the bars. Negative values move the axis to the right.
axis(2, line = -14)


Another option, which results in something closer to the barplot when
not using the 'asp' argument, is to adjust the 'width' argument to
increase the horizontal size of the bars:

# Draw the barplot and increase the width of the bars
# Do not draw the axes
barplot(dataSeries, asp=1, width = 8, axes = FALSE)

# Now draw the y axis
axis(2, at = seq(0, 12, 2))

Note however, that in this example, the vertical dimension is
shortened, since the 'asp' argument is still trying to properly set
the aspect ratio and the larger bar width increases the range of the x
axis.


Finally(?), another option to consider is to set par(pty = s) as an
alternative to using 'asp = 1'. This results in a square plot region,
rather than a maximal (typically rectangular) one. See ?par for more
info here. In this case:

par(pty = s)
barplot(dataSeries)

This might result in better looking arcs for your corners.

Without having your modified barplot() function, it is hard to know
which might work best here, but hopefully this might provide some
possibilities.

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


Re: [R] axis placement with stacked barplots and the asp=1 parameter

2005-01-21 Thread Uwe Ligges
Kavithan Siva wrote:
Hi
Here's some example code which illustrates the issue:
dataSeries-array(0, c(5, 2))
dataSeries[1, 1] - 5
dataSeries[2, 1] - 5
dataSeries[3, 1] - 0
dataSeries[4, 1] - 2
dataSeries[5, 1] - 0
dataSeries[1, 2] - 7
dataSeries[2, 2] - 0
dataSeries[3, 2] - 0
dataSeries[4, 2] - 0
dataSeries[5, 2] - 1
barplot(dataSeries, asp=1)
Removing the asp=1 parameter produces a correct looking plot. I need to
use the asp=1 parameter because I was re-writing the barplot function to
create stacked charts with rounded corners (instead of rectangles). For
the arc at the corners of the bars to look correct I need asp=1. I've
attached a .ps file to show you what I was trying to achieve.
Marc Schwartz already made some good points.
I'd like to suggest to build your new function up on grid using 
viewports in order to finally get a clean implementation.

Uwe Ligges

Thanks
Kav
Kavithan Siva
Prytania Investment Advisors LLP
105 Ladbroke Grove, London, W11 1PG
Tel: +44 20 7616 8475   Fax: +44 20 7616 8472
Prytania Investment Advisors LLP is regulated by the FSA
-Original Message-
From: Uwe Ligges [mailto:[EMAIL PROTECTED] 
Sent: Friday, January 21, 2005 11:52 AM
To: Kavithan Siva
Cc: r-help@stat.math.ethz.ch
Subject: Re: [R] axis placement with stacked barplots and the asp=1
parameter

Kavithan Siva wrote:

Hi,
I'm currently using barplot to generate vertically stacked bar charts.
I'd like to be able to use the asp=1 parameter with barplot(), but
doing this causes the y axis to be placed on the far left as shown in
the attachment demo.pdf.

See the posting guide, some file types (including pdf) will be omitted 
from your messages to R-help. You might want to specify a short but 
easily reproducible examples in 2-5 lines of code.

Why do you want to use asp with a barplot???
Uwe Ligges

I could get around this by using the negative values for the line
parameter of the axis() function. I'd rather not do this and imagine
I'm
doing something wrong. Any help would be much appreciated.
Thanks
Kav
---
This e-mail may contain confidential and/or privileged information. If
you are not the 

intended recipient (or have received this e-mail in error) please
notify the sender 

immediately and destroy this e-mail. Any unauthorised copying,
disclosure or distribution 

of the material in this e-mail is strictly forbidden. The Prytania
Group has taken every 

reasonable precaution to ensure that any attachment to this e-mail has
been swept for 

viruses. However, we cannot accept liability for any damage sustained
as a result of 

software viruses and would advise that you carry out your own virus
checks before 

opening any attachment.


__
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
 
 ---
This e-mail may contain confidential and/or privileged inf...{{dropped}}
__
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