在格子图中格式化轴标签 [英] Formatting axis labels in lattice plot

查看:155
本文介绍了在格子图中格式化轴标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将y轴标签格式更改为通常的( xxx.xxx )而不是科学的?

  df < -  read.table(textConnection(
ypogr_act amount cumSum
2012-09-20 30.00 30.00
2012 -11-19 1834.69 1864.69
2012-11-30 2915.88 4780.57
2012-11-30 2214.98 6995.55
2012-12-18 21815.00 28810.55
2012-12-19 315000.00 343810.55
2012-12-21 1050.00 344860.55
2012-12-28 1300.00 346160.55
2013-01-10 1836.77 347997.32
2013-01-17 122193.00 470190.32
2013- (格)
图书馆(动物园)
x< b) ; - 动物园(df [2:3],df $ ypogr_act)

win.graph(12,8)

print(xyplot(x,lwd = 2,xlab ='Μήνας',
col = c(rgb(127,201,127,max = 255),rgb(56,108, 176,max = 255))
scales = list(y = list(rot = 0,abbreviate = FALSE))))
trellis.focus(panel,1,1,highlight = F )
panel.grid(h = -1,v = 0,col =gray,lty = 3)
trellis.unfocus()
pre

解决方案

编辑: 更简单的解决方案: options(scipen = 10)然后运行你的代码。如果只是临时改变选项,你可以这样做:

  oscipen<  -  options(scipen = 10)
##<您的绘图代码>
options(oscipen)






是一个简单的解决方案,但这是我会做的:

  ##编写一个自定义的轴注释函数
# #(使用latticeExtra :: xscale.components.log()等作为模板)
yscale.components.custom< - function(lim,logsc = FALSE,...){
ans < - yscale.components.default(lim,logsc = logsc,...)
ans $ left $ labels $ labels< - format(ans $ left $ labels $ at,digits = 3,scientific = 10 )
ans
}

##通过xyplot的'yscale.components ='参数指向自定义的函数
xyplot(x,lwd = 2,xlab = (
col = c(rgb(127,201,127,max = 255),rgb(56,108,176,max = 255)),
scales = list( y = list(rot = 0,abbreviate = FALSE)),
yscale.components = yscale.components.custom)


How can I change the y-axis labels format to usual (xxx.xxx) instead of scientific, in the following plot?

df <- read.table(textConnection("
    ypogr_act  amount           cumSum
2012-09-20     30.00              30.00
2012-11-19   1834.69            1864.69
2012-11-30   2915.88            4780.57
2012-11-30   2214.98            6995.55
2012-12-18  21815.00           28810.55
2012-12-19 315000.00          343810.55
2012-12-21   1050.00          344860.55
2012-12-28   1300.00          346160.55
2013-01-10   1836.77          347997.32
2013-01-17 122193.00          470190.32
2013-03-22 415000.00          885190.32
")->con,header=T);close(con)

library(lattice)
library(zoo)
x <- zoo(df[2:3], df$ypogr_act)

win.graph(12,8)

print( xyplot(x, lwd=2,xlab='Μήνας',
              col=c(rgb(127, 201, 127, max = 255),rgb(56, 108, 176, max = 255)),
              scales = list(y=list(rot = 0,abbreviate=FALSE)) ))
trellis.focus("panel", 1, 1, highlight = F)
panel.grid(h = -1, v = 0, col = "grey", lty = 3)
trellis.unfocus()

解决方案

Edit: There is a simpler solution: just set options(scipen=10) and then run your code. To only temporarily change the option, you can do something like this:

oscipen <- options(scipen=10)
## <Your plotting code>
options(oscipen)


There may be a simpler solution, but here's what I'd do:

## Write a customized axis annotation function 
## (Uses latticeExtra::xscale.components.log() et al. as templates.)
yscale.components.custom <- function (lim, logsc = FALSE, ...) {
    ans <- yscale.components.default(lim, logsc = logsc, ...)
    ans$left$labels$labels <- format(ans$left$labels$at, digits=3, scientific=10)
    ans
}

## Point to the customized function via xyplot's 'yscale.components=' argument
xyplot(x, lwd=2,xlab='???a?',
       col=c(rgb(127, 201, 127, max = 255),rgb(56, 108, 176, max = 255)),
       scales = list(y=list(rot = 0,abbreviate=FALSE)),
       yscale.components = yscale.components.custom)

这篇关于在格子图中格式化轴标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆