[英]Change scale format for y axis in lattice plot
Hi everybody I am making a graphic with lattice package and it works fine but I have a little problem with format of y axis. 大家好我正在制作一个带有格子包的图形,它工作正常,但我的y轴格式有点问题。 The data used for this graphic is saved in
a
, a list with four numeric variables and one factor variable (In the final part I add the dput
version). 用于此图形的数据保存在
a
包含四个数字变量和一个因子变量的列表中(最后一部分我添加了dput
版本)。 The code used to make my graph is the next: 用于制作我的图表的代码是下一个:
library(lattice)
DD=barchart(a1 ~ a5,a)
DD
I got this graphic with this code: 我用这段代码得到了这个图形:
In this graph the scale of y axis shows the complete numbers for example 2000000, 4000000, etc. I don't know if it is possible to create a function or maybe any option to get values in y axis like these 2,000,000 until 8,000,000. 在此图中,y轴的比例显示完整的数字,例如2000000,4000000等。我不知道是否可以创建一个函数或任何选项来获取y轴中的值,如2,000,000直到8,000,000。 The
dput()
version of a
is the next: 该
dput()
的版本, a
是下一个:
structure(list(a1 = c(560492.29, 1433973.37, 3016748.66, 4241217.73,
6251742.27, 6757161.24, 7408081.05, 7899980.33), a2 = 1:8, a3 = c(0,
0.00793734405263048, 0.0129172080248807, 0.0324335034787285,
0.0397094648625047, 0.0555107413716237, 0.0521541081141384, 0.0515512600016815
), a4 = c(0.0142731668976214, 0.010460445301017, 0.0928151568317925,
0.0707344020275045, 0.0303915279604129, 0.0517968992552855, 0.0202481585970229,
0.0253165187311296), a5 = structure(1:8, .Label = c("abr 2013",
"may 2013", "jun 2013", "jul 2013", "ago 2013", "sep 2013", "oct 2013",
"nov 2013"), class = "factor")), .Names = c("a1", "a2", "a3",
"a4", "a5"))
Many thanks for your help. 非常感谢您的帮助。
You can specify your custom formatter, for example: 您可以指定自定义格式化程序,例如:
comma_fomatter <- function (lim, logsc = FALSE, at = NULL, ...)
{
ans <- yscale.components.default(lim = lim, logsc = logsc,
at = at, ...)
xx = as.numeric(ans$left$labels$labels)
ans$left$labels$labels <- formatC(xx, format="fg",big.mark = ",")
ans
}
Then : 然后 :
barchart(a1 ~ a5,xx, yscale.components =comma_fomatter )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.