简体   繁体   中英

How to add commas to numbers on axes in matplot - R

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

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 = ","))

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM