0

I want to build a black and white bar graph, that shows groups of column in line order. Eg. using the matrix below, I want to have 4 sets of columns in the order (XX,YY):

first set: (A,A)(A,B)(A,C)(A,D)
second set: (B,A)(B,B)(B,C)(B,D)
third set: (C,A)(C,B)(C,C)(C,D)
fourth set: (D,A)(D,B)(D,C)(D,D)

[1] Values:

   A    B   C   D
A  0    40  91  19
B  84   0   99  26
C  57   901 0   20
D  37   186 196 0

I use this R script [3], but the problem is that it is building the graph in column order. Eg,

first set: (A,A)(B,A)(C,A)(D,A)
Second set: (A,B)(B,B)(C,B)(D,B)
Third set: (A,C)(B,C)(C,C)(D,C)
fourth set: (A,D)(B,D)(C,D)(D,D)

How can I build this graph in column order and in black&white and using patterns?

[3] R script

# Read values from tab-delimited autos.dat
autos_data <- read.table("autos_data.dat", header=T, sep="\t")

# Graph autos with adjacent bars using rainbow colors
barplot(as.matrix(autos_data), main=NULL, ylab= "Size", beside=TRUE, col=rainbow(5))

# Place the legend at the top-left corner with no frame using rainbow colors
legend("topleft", c("A","B","C","D"), cex=0.6, bty="n", fill=rainbow(5));
xeon123
  • 819
  • 1
  • 10
  • 25
  • `t`ranspose your matrix? – Henrik Nov 12 '15 at 19:40
  • @Henrik ok. But theres is a command for do it in R, or I need to transpose the data in the dat file? – xeon123 Nov 12 '15 at 22:42
  • @xeon123 - `t()` is the `transpose` function that Henrik was noting when he said `t`ranspose – thelatemail Nov 13 '15 at 04:54
  • @thelatemail I have `transpose`. Now I would like to add a label to the datapoints c("A","B","C","D"). Eg, Brand of the car: A, B, C, D. And I also would like that the graph would come up without colours. How I do this? – xeon123 Nov 13 '15 at 05:11
  • @xeon123 - the names will be taken automatically from `colnames(dat)`, or you can specify them manually with `names.arg=`. Setting `col=NA` likewise will remove the colours of the bars. e.g. `barplot(t(dat), beside=TRUE, names.arg=c("A","B","C","D"), col=NA)` – thelatemail Nov 13 '15 at 05:15
  • @thelatemail but I want to add a label Brand of the car over the names c=("A","B","C","D") – xeon123 Nov 13 '15 at 05:29
  • @xeon123 - you'll need to do something like this: [barplot-x-axis-labels-with-hierarchical-grouping-variables-in-separate-rows](http://stackoverflow.com/questions/18776078/barplot-x-axis-labels-with-hierarchical-grouping-variables-in-separate-rows/18776424#18776424) – thelatemail Nov 13 '15 at 05:31
  • @thelatemail I think this is not what I want. What I want is to format the label of the datapoints in order to also have a title on it. – xeon123 Nov 13 '15 at 05:41
  • @xeon123 - I'm afraid you'll have to edit your question to provide a clear example of what you want, as going back and forth in the comments is not overly productive. – thelatemail Nov 13 '15 at 06:04
  • @thelatemail thanks. For now, I will forget this small adjustment. – xeon123 Nov 13 '15 at 06:05

0 Answers0