Gmichael
Gmichael

Reputation: 568

R not colouring bar plot

I am doing a graphical visualization of various parts of my questionnaire. We are using the RGB system to coordinate colours with Excel However my bar plots aren't being coloured, only the first colour of the colouring vector is being used.

So instead of

barplot(c(1, 1, 1), axes=T, col=c("#806000","#C6E0B4","#FFC000"),names.arg=c("test1","test2","test3"))

I am ending up with all three bars being the colour "#806000".

Here is the code for my graph (DATA_tot is the entire data table for my questionnaire):

barplot(
  cbind(
    length(which(DATA_tot$A014_18==2)),
    length(which(DATA_tot$A014_02==2)),   
    length(which(DATA_tot$A014_01==2)),
    length(which(DATA_tot$A014_03==2))
    ),
  main="Frage 4a",
  col=c("grey","#806000","#C6E0B4","#FFC000"),
  ylab="Anzahl der Betriebe",
  names.arg=c("keine \n Änderungen","Streuwiesen","einmähdige \n 
Wiesen","Hutweiden"), 
  ylim=c(0,1400),
  cex.axis=0.8, cex.names=0.6
  )

Has anybody ever experienced this problem or found a way around it? I am explicitly looking for solutions with barplot (for other reasons).

Upvotes: 0

Views: 100

Answers (1)

Cettt
Cettt

Reputation: 11981

try to use c instead of cbind:

barplot(
  c(
    length(which(DATA_tot$A014_18==2)),
    length(which(DATA_tot$A014_02==2)),   
    length(which(DATA_tot$A014_01==2)),
    length(which(DATA_tot$A014_03==2))
    ),
  main="Frage 4a",
  col=c("grey","#806000","#C6E0B4","#FFC000"),
  ylab="Anzahl der Betriebe",
  names.arg=c("keine \n Änderungen","Streuwiesen","einmähdige \n 
Wiesen","Hutweiden"), 
  ylim=c(0,1400),
  cex.axis=0.8, cex.names=0.6
  )

Upvotes: 2

Related Questions