1

I'm having trouble creating bar plots in R. The odd thing is that I've used the same script before with different variables without any issues, so I don't really know what is going on (I'm fairly new to R).

The code I've been using is (with transposed matrix):

barplot(StandtF, main="h2, c2, e2 by Mod FEMALES",
xlab="Social Support", ylab="% of Var", beside=TRUE, axesnames=TRUE,
names.arg=c("No","Yes"),
col=c("red","green","darkblue"))
    legend("topleft",c("h2","c2","e2"),fill=c("red","green","darkblue") )

And the error message that's returned is:

Error in barplot.default(StandtM, main = "h2, c2, e2 by Mod FEMALES", xlab = "Social Support", : incorrect number of names In addition: Warning message: In plot.window(xlim, ylim, log = log, ...) : "axesnames" is not a graphical parameter

I've looked around at different posts, but nothing so far has been helpful. And as said, the script has worked fine previously.

Any help would be greatly appreciated.

PKumar
  • 10,971
  • 6
  • 37
  • 52
ambxc1
  • 11
  • 1
  • 2
  • I have answered your question, nevertheless it would be helpful if you provide how does your data look like. – R18 May 15 '17 at 13:20
  • You have a 'typo' in your code: use `axisnames = TRUE` in stead of `axes....` – KoenV May 15 '17 at 13:53

1 Answers1

1

You gave to the function two names names.arg=c("No","Yes")and you have three levels according to your legend and the colors defined. So, you need a vector with three names.

R18
  • 1,476
  • 1
  • 8
  • 17
  • I'm trying to create a grouped bar plot. I have values for h2, c2 and e2 under both yes and no. Below is the output from my script: – ambxc1 May 15 '17 at 14:47
  • h2m 0.2213663 c2m 0.004542067 e2m 0.7740917 h2mM 0.2408153 c2mM 0.00546826 e2mM 0.7537164 h2f 0.4621275 c2f 0.0985327 e2f 0.4393398 h2fM 0.4838181 c2fM 0.1024018 e2fM 0.4137801 This is what I'm trying to plot, with h2fM, c2fM, and e2fM being categorised at 'yes' – ambxc1 May 15 '17 at 14:53
  • The way you displayed the information doesn't help to see how data looks like. If I have understood well your question, this answer may help you: http://stackoverflow.com/questions/17721126/simplest-way-to-do-grouped-barplot – R18 May 16 '17 at 07:34