[R] how can I plot bar plots with all the bars (negative and positive) in the same direction????
Joshua Wiley
jwiley.psych at gmail.com
Fri Sep 3 19:51:33 CEST 2010
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]
<zoppolig at 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: zoppolig at mail.nih.gov
> ______________________________________________
> 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.
>
--
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/
More information about the R-help
mailing list