[R] barplot usage

2005-04-13 Thread Antonio Olinto
Hi,

I’m trying to make a barplot with the following dataframe, with information on
relative frequency per sediment type (ST) for some species:

Species  ST1  ST2  ST3
SP_A 10   6030
...


At x-axis are (should be ...) the species names and at y-axis the frequency per
sediment, in stacked bars.

I tried to use barplot command but with no results. Could anyone help me on 
this?

Thanks in advance,

Samantha



-
WebMail Bignet - O seu provedor do litoral
www.bignet.com.br

__
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] barplot usage

2005-04-13 Thread Marc Schwartz
On Wed, 2005-04-13 at 19:05 -0300, Antonio Olinto wrote:
 Hi,
 
 Im trying to make a barplot with the following dataframe, with information 
 on
 relative frequency per sediment type (ST) for some species:
 
 Species  ST1  ST2  ST3
 SP_A 10   6030
 ...
 
 
 At x-axis are (should be ...) the species names and at y-axis the frequency 
 per
 sediment, in stacked bars.
 
 I tried to use barplot command but with no results. Could anyone help me on 
 this?
 
 Thanks in advance,
 
 Samantha

You could use something like the following (presuming that your data is
a data frame called 'df'):

  barplot(t(df[2:4]), names.arg = as.character(df$Species))

Note that the row values that you have (excluding the Species name) need
to be rotated 90 degrees as follows:

 t(df[2:4])
 1 ...
ST1 10 ...
ST2 60 ...
ST3 30 ...

In this case, each column represents the segments of each stacked bar
(or if you set 'beside = TRUE', the individual bars in a group of bars)

Then the labels below each bar in the plot come from the df$Species
column. I used as.character(df$Species) presuming that this column might
be a factor. If not, you can eliminate the use of as.character() here.

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