[R] how can I plot bar plots with all the bars (negative and
(Ted Harding)
Ted.Harding at manchester.ac.uk
Fri Sep 3 20:08:37 CEST 2010
On 03-Sep-10 17:12:55, 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?
>
> Thanks!
> Gabriele Zoppoli, MD
It's not completely clear what you want to see, given the vector.
However, the reason you are seeing the bars go upwards and
downwards is given at the beginning of '?barplot':
barplot(height, width = 1, space = NULL, ... )
Therefore, if x is a vector of positive and negative numbers,
barplot(x) will correctly draw bars with negative heightslues
(downwards) at negative values of x, and with positive heights
(upwards) for positive values of x.
On the other hand, possibly you want to see a barplot which
corresponds to a histogram, i.e. for each distinct value of x
you get a bar pointing upwards with height equal to the count
of that value.
For example:
set.seed(54321)
x<-sample(((-3):4),100,replace=TRUE)
x ### Have a look at the values in x
barplot(x) ### A barplot with bar heights given by x
barplot(table(x)) ### a barplot of the counts of the values of x
Hoping this helps,
Ted.
--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 03-Sep-10 Time: 19:08:34
------------------------------ XFMail ------------------------------
More information about the R-help
mailing list