-1

I want to add commas to the y-axis on my plot, but what I have tried so far is not working:

matplot(X, Y, type = "l", col = "green", xlab = "Time (years)", ylab = "Cost", main = "BLANK", ylim = (30000,60000), xlim = c(0,15))

is what I have.

Not sure how to add commas to the 30,000 - 60,000 which should appear on the y-axis.

EDIT: Sorry, what I meant in tags for matplot was this: http://stat.ethz.ch/R-manual/R-patched/library/graphics/html/matplot.html

David Arenburg
  • 91,361
  • 17
  • 137
  • 196
Islands
  • 255
  • 4
  • 10
  • You really should include a [minimal, reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). Without sample data (`X` or `Y`), we don't know exactly what you're looking at. Most likely you will need to suppress the default axis and do an explicit call to `axis` yourself. – MrFlick Jun 25 '14 at 20:21
  • @MrFlick: Ah. Sorry. I'm using real data and I can't post that. I should have done as user David Arenburg did. – Islands Jun 25 '14 at 20:34
  • 1
    Indded. Sample data does't have to be real data. Just enough to reproduce the problem. – MrFlick Jun 25 '14 at 20:34

1 Answers1

5

You could use a combination of yaxt = "n", axis and prettyNum as in

Y <- seq(30000, 60000, 2000)
X <- 0:15
matplot(X, Y, type = "l", col = "green", xlab = "Time (years)", ylab = "Cost", main = "BLANK", yaxt = "n")
axis(2, Y, labels = prettyNum(Y, big.mark = ","))

enter image description here

David Arenburg
  • 91,361
  • 17
  • 137
  • 196