搜索
查看: 2392|回复: 0

[R] 试水贴-R语言画仪表盘

[复制链接]

2

主题

2

帖子

23

积分

新手上路

Rank: 1

积分
23
发表于 2016-8-31 15:22:54 | 显示全部楼层 |阅读模式
本帖最后由 davexu 于 2016-8-31 15:32 编辑

jpeg("./gauge3.jpg",4000,4000)
# gauge -------------------------------------------------------------------

indicate=round(runif(1,30,35))
indicateage=round(runif(1,20,45))

realage=round(runif(1,20,45))
oversameage=round(runif(1,0,100))
overallage=round(runif(1,0,100))

data_to_angel <- function(class,num){
  # trans  numbers to angle,class 1 for the big indicator, class 2 for the small ones
  if (class==1){
    if (num >45) num=45
    if (num <20) num=20
[Python] 纯文本查看 复制代码

    numa <- num - 32.5
    ang <- numa * 270/25
  }else if (class == 2){
    ang <- (num-50) * 270/100
  }
  return(ang)
}
loc <- function(class,num,adjust=30,length=c(0.85*0.618/4,0.85)){
  #for all angle
  afang <- data_to_angel(class,num)
  angel1 <- afang/180 * pi
  angel2 <- (afang + adjust)/180 * pi
  angel3 <- (afang - adjust)/180 * pi
  xx <- c(0,sin(angel2) * length[1],sin(angel1) * length[2],sin(angel3) * length[1])
  yy <- c(0,cos(angel2) * length[1],cos(angel1) * length[2],cos(angel3) * length[1])
  location <- data.frame(x=xx,y=yy)
  return(location)
}
#pie background

pie(x=c(27,54,54,90,54,54,27),labels=c(""),radius = 1,border = F,clockwise = T,col=c("#A6BDDB","#67A9CF","#3690C0","white","#ECE2F0","#D0D1E6","#A6BDDB"))
par(new=T)
#pie add digital
pie(x=c(54,54,72,72,54,54),labels=c(35,40,"","",25,30),radius = 1,border = F,clockwise = T,col=rainbow(3,alpha = 0),cex=15)
# pie add digital
par(new=T)
pie(x=c(90,90,90,90),labels=c("","45","20",""),radius = 1,border = F,clockwise = T,col=rainbow(3,alpha = 0),cex=15)
# generate gauge
par(new=T)
pie(x=c(27,54,54,90,54,54,27),labels=c(""),radius = 0.85,border = F,clockwise = T,col="white")
par(new=T)
polygon(x=loc(1,realage)$x,y=loc(1,realage)$y,lwd=13,col="#F46D4388",border = F)




上一篇:小骆驼学习笔记第1章
下一篇:试水贴-python html转pdf
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|小黑屋|生信技能树    

GMT+8, 2019-6-16 19:37 , Processed in 0.077938 second(s), 28 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.