[R] how can I plot bar plots with all the bars (negative and positive) in the same direction????

2010-09-03 Thread Zoppoli, Gabriele (NIH/NCI) [G]
Dear r-help mailing list,

this seems stupid, but I actually don't find the solution:

if I have a vector of numbers x of length n, ranging, say, from -3 to 4, if I do

barplot (x)

all the values below 0 go downwards, and all the positive values go upward. How 
can I make them all begin from the minimum pointing upwards?

Thanks!


Gabriele Zoppoli, MD
Ph.D. Fellow, Experimental and Clinical Oncology and Hematology, University of 
Genova, Genova, Italy
Guest Researcher, LMP, NCI, NIH, Bethesda MD

Work: 301-451-8575
Mobile: 301-204-5642
Email: zoppo...@mail.nih.gov
__
R-help@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.


Re: [R] how can I plot bar plots with all the bars (negative and positive) in the same direction????

2010-09-03 Thread Peng, C

In the bar plot, the vertical axis is a numerical axis representing the
frequency (the height of the vertival bar -= frequency). If you really want
to have vertical bar corresponding to the negative values go downward, you
need to make your own function to achieve the goal.
-- 
View this message in context: 
http://r.789695.n4.nabble.com/how-can-I-plot-bar-plots-with-all-the-bars-negative-and-positive-in-the-same-direction-tp2526006p2526021.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] how can I plot bar plots with all the bars (negative and positive) in the same direction????

2010-09-03 Thread Joshua Wiley
Dear Gabriele,

I suspect the reason you are having difficulty finding the solution is
because barplots were meant to be anchored at 0.

What information are you really trying to convey?  There is probably a
very clear, aesthetically pleasing way to achieve your goal without a
barplot.

For instance, what about a simple scatter plot?

dat - (-3:4)
plot(x = 1:length(dat), y = dat, xaxt = n, xlab = My Groups)
axis(side = 1, at = 1:length(dat), labels = LETTERS[1:8])

Alternately, you could add the minimum to your data so it started at 0...

barplot(dat + abs(min(dat)))

Hadley will never forgive me for mentioning this but, if you have a
desperate need to use bars that are anchored at the minimum value, you
could use geom_rect() in package ggplot2...

mydf - data.frame(x = 1:8, y = dat)
library(ggplot2)
ggplot(mydf, aes(xmin = x, xmax = x + 1, ymin = min(y), ymax = y)) + geom_rect()

HTH,

Josh

On Fri, Sep 3, 2010 at 10:12 AM, Zoppoli, Gabriele (NIH/NCI) [G]
zoppo...@mail.nih.gov wrote:
 Dear r-help mailing list,

 this seems stupid, but I actually don't find the solution:

 if I have a vector of numbers x of length n, ranging, say, from -3 to 4, if I 
 do

 barplot (x)

 all the values below 0 go downwards, and all the positive values go upward. 
 How can I make them all begin from the minimum pointing upwards?

 Thanks!


 Gabriele Zoppoli, MD
 Ph.D. Fellow, Experimental and Clinical Oncology and Hematology, University 
 of Genova, Genova, Italy
 Guest Researcher, LMP, NCI, NIH, Bethesda MD

 Work: 301-451-8575
 Mobile: 301-204-5642
 Email: zoppo...@mail.nih.gov
 __
 R-help@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.




-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/

__
R-help@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.


Re: [R] how can I plot bar plots with all the bars (negative and positive) in the same direction????

2010-09-03 Thread David Winsemius


On Sep 3, 2010, at 1:12 PM, Zoppoli, Gabriele (NIH/NCI) [G] wrote:


Dear r-help mailing list,

this seems stupid, but I actually don't find the solution:

if I have a vector of numbers x of length n, ranging, say, from -3  
to 4, if I do


barplot (x)

all the values below 0 go downwards, and all the positive values go  
upward. How can I make them all begin from the minimum pointing  
upwards?





 grp.n -c(0, -1, -2, -3, -5, -1,  3, -2,  2,  0)
 barplot(grp.n-min(grp.n), axes=FALSE)
 axis(2, grp.n-min(grp.n), labels=as.character(grp.n))


Compare
 barplot(grp.n, axes=FALSE)


--
David Winsemius, MD
West Hartford, CT

__
R-help@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.


Re: [R] how can I plot bar plots with all the bars (negative and positive) in the same direction????

2010-09-03 Thread Robert Baer
As is often the case in R, just because you shouldn't do something, doesn't 
mean you can't do it.  Still, I'd urge you to consider the visual honesty 
of what you propose.


If you're still insistent:
dat - (-3:4)
dat1=dat-min(dat)
barplot(dat1,axes=FALSE)
axis(2,dat1,labels=dat)

Typically, zero is a reference point and/or the identity element for 
addition.  Your plot audience will interpret it this way.  If you want to 
look at difference scores from the minimal value, shouldn't that be exactly 
how you label your y-axis, and not with the pre-transformed numbers?


Are you still sure you don't like the default behavior?

Rob Baer


- Original Message - 
From: Zoppoli, Gabriele (NIH/NCI) [G] zoppo...@mail.nih.gov

To: r-help@r-project.org
Sent: Friday, September 03, 2010 12:12 PM
Subject: [R] how can I plot bar plots with all the bars (negative and 
positive) in the same direction




Dear r-help mailing list,

this seems stupid, but I actually don't find the solution:

if I have a vector of numbers x of length n, ranging, say, from -3 to 4, 
if I do


barplot (x)

all the values below 0 go downwards, and all the positive values go 
upward. How can I make them all begin from the minimum pointing upwards?


Thanks!


Gabriele Zoppoli, MD
Ph.D. Fellow, Experimental and Clinical Oncology and Hematology, 
University of Genova, Genova, Italy

Guest Researcher, LMP, NCI, NIH, Bethesda MD

Work: 301-451-8575
Mobile: 301-204-5642
Email: zoppo...@mail.nih.gov
__
R-help@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@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.


Re: [R] how can I plot bar plots with all the bars (negative and positive) in the same direction????

2010-09-03 Thread John Kane
I believe that you will have to draw them in ggplot2 as someone mentioned or in 
base graphics.  Here is a rough first attempt that may give you some ideas.

xx - -3:4
yy - rep(-3,length(xx))
plot(xx,xx,  type=n, xlim=c(-4, 5))
rect(xx, yy, xx+.5, xx )


--- On Fri, 9/3/10, Zoppoli, Gabriele (NIH/NCI) [G] zoppo...@mail.nih.gov 
wrote:

 From: Zoppoli, Gabriele (NIH/NCI) [G] zoppo...@mail.nih.gov
 Subject: [R] how can I plot bar plots with all the bars (negative and 
 positive) in the same direction
 To: r-help@r-project.org r-help@r-project.org
 Received: Friday, September 3, 2010, 1:12 PM
 Dear r-help mailing list,
 
 this seems stupid, but I actually don't find the solution:
 
 if I have a vector of numbers x of length n, ranging, say,
 from -3 to 4, if I do
 
 barplot (x)
 
 all the values below 0 go downwards, and all the positive
 values go upward. How can I make them all begin from the
 minimum pointing upwards?
 
 Thanks!
 
 
 Gabriele Zoppoli, MD
 Ph.D. Fellow, Experimental and Clinical Oncology and
 Hematology, University of Genova, Genova, Italy
 Guest Researcher, LMP, NCI, NIH, Bethesda MD
 
 Work: 301-451-8575
 Mobile: 301-204-5642
 Email: zoppo...@mail.nih.gov
 __
 R-help@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@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.