楼主: zyz0329
4197 14

[问答] 这个图怎么做的 求指点 [推广有奖]

  • 1关注
  • 37粉丝

已卖:328份资源

院士

29%

还不是VIP/贵宾

-

威望
0
论坛币
83453 个
通用积分
371.2642
学术水平
58 点
热心指数
92 点
信用等级
41 点
经验
494 点
帖子
1116
精华
0
在线时间
5697 小时
注册时间
2010-12-1
最后登录
2025-11-25

楼主
zyz0329 在职认证  发表于 2014-5-25 14:49:37 |AI写论文
100论坛币
这个图怎么做的 求指点

U10235P31T1D19216734F6000DT20140525060701.jpg (29.83 KB)

U10235P31T1D19216734F6000DT20140525060701.jpg

最佳答案

zhangyangsmith 查看完整内容

A piece-by-piece solution using {graphics} only:Result:
关键词:求指点 怎么做

本帖被以下文库推荐

沙发
zhangyangsmith 发表于 2014-5-25 14:49:38
A piece-by-piece solution using {graphics} only:
  1. # Data for plotting
  2. head(dfPlt)
  3. #       mnt  hrl              prv
  4. # 北京 1650 16.9 <U+5317><U+4EAC>
  5. # 上海 1620 14.0 <U+4E0A><U+6D77>
  6. # 广东 1550 15.0 <U+5E7F><U+4E1C>
  7. # 新疆 1520 15.2 <U+65B0><U+7586>
  8. # 天津 1500 15.0 <U+5929><U+6D25>
  9. # 江苏 1480 13.0 <U+6C5F><U+82CF>

  10. # Function to add a fan-shape with text inside and outside in the plot
  11. pltFan <-
  12.   function(cnt.arc, arc, r.in, r.out, text.in = character(0), text.out = character(0), text.in.cex = 0.5, text.out.cex = text.in.cex, ...)
  13.   {
  14.     # Fan-shape
  15.     polygon(c(r.in*cos(cnt.arc - arc/2), r.in*cos(cnt.arc + arc/2), r.out*cos(cnt.arc + arc/2), r.out*cos(cnt.arc - arc/2)), c(r.in*sin(cnt.arc - arc/2), r.in*sin(cnt.arc + arc/2), r.out*sin(cnt.arc + arc/2), r.out*sin(cnt.arc - arc/2)), ...)
  16.     # Text inside
  17.     text((r.in - par()$cxy[2]*text.in.cex)*cos(cnt.arc), (r.in - par()$cxy[2]*text.in.cex)*sin(cnt.arc), text.in, adj = c(0.5, 0.5), srt = cnt.arc/2/pi*360 - 90, cex = text.in.cex)
  18.     # Text outside
  19.     text((r.out + par()$cxy[2]*text.out.cex)*cos(cnt.arc), (r.out + par()$cxy[2]*text.out.cex)*sin(cnt.arc), text.out, adj = c(0.5, 0.5), srt = cnt.arc/2/pi*360 - 90, cex = text.out.cex)
  20.   }

  21. # Number of records to plot
  22. iNbar <- nrow(dfPlt)
  23. # Optionally, map additional font - Windows only
  24. windowsFonts(KT = windowsFont("KaiTi"))
  25. # Plot in .png format
  26. png("salary.png", width = 960, height = 960)
  27. # Maximizing the plot area
  28. par(mar = c(0, 0, 0, 0))
  29. # Call plot.new with a few settings
  30. plot(c(-2, 2), c(-2, 2), type = "n", axes = F, xlab = "", ylab = "", asp = 1, xlim = c(-2, 2), ylim = c(-2, 2))
  31. # Do the plot
  32. sapply( 0:(iNbar - 1), function(i)
  33.   {
  34.   # Text inside
  35.   pltFan(cnt.arc = pi/2 - (i*2*pi/(iNbar + 1) + 2*pi/(iNbar + 1)*(1/4 + 1/8 + 1/4)/2), arc = 2*pi/(iNbar + 1)*(1/4 + 1/8 + 1/4), r.in = 1, r.out = 2, text.in = dfPlt[i + 1, "prv"], text.out = NULL, col = NULL, border = NA, text.in.cex = 1)
  36.   # Monthly data
  37.   pltFan(cnt.arc = pi/2 - (i*2*pi/(iNbar + 1) + 2*pi/(iNbar + 1)/8), arc =  2*pi/(iNbar + 1)/4, r.in = 1, r.out = dfPlt[i + 1, "mnt"]/1000, text.in = NULL, text.out = as.character(dfPlt[i + 1, "mnt"]), text.out.cex = 1, col = "orange", border = NA)
  38.   # Hourly data
  39.   pltFan(cnt.arc = pi/2 - (i*2*pi/(iNbar + 1) + 2*pi/(iNbar + 1)*(2 + 1 + 1)/8), arc =  2*pi/(iNbar + 1)/4, r.in = 1, r.out = dfPlt[i + 1, "hrl"]/20 + 1, text.out.cex = 1, text.in = NULL, text.out = as.character(dfPlt[i + 1, "hrl"]), col = "yellow", border = NA)
  40.   } )
  41. # Legend and other texts in the plot
  42. legend(2, -1.5, c("月最低工资标准", "小时最低工资标准"), col = c("orange", "yellow"), bty = "n", cex = 1.25, pt.cex = 1.2, pch = c(15, 15), xjust = 1, yjust = 1) -> lgnd
  43. # If no font mapping is done, remove the family option
  44. text(lgnd$rect$left, lgnd$rect$top - lgnd$rect$h, "注:数字为截至2014年\n5月1日的执行标准", adj = c(0, 1), cex = 1.25, family = "KT")
  45. text(-2.1, 1.75, "全国各省(区、直辖市)\n2014年最低工资标准", cex = 1.75, adj = c(0, 1))
  46. text(-2.1, 1.75 - par()$cxy[2]*4, "(单位:元)", cex = 1.25, adj = c(0, 1))
  47. dev.off()
复制代码
Result: salary.png
已有 2 人评分经验 论坛币 学术水平 热心指数 收起 理由
jmpamao + 60 + 60 + 3 精彩帖子
dxystata + 40 + 50 + 3 + 2 精彩帖子

总评分: 经验 + 100  论坛币 + 110  学术水平 + 6  热心指数 + 2   查看全部评分

藤椅
gyqznufe 发表于 2014-5-25 15:00:44
不错的设计,就是图的中间空的太多,占地儿啊。希望这个图对你有用:http://excelpro.blog.sohu.com/262660652.html
知常容·容乃公·公乃王!
创新源于学、问、思、行、果!
言传身教,请用事实与数据说话!
舍而得之:福、禄、寿、喜、财

板凳
yywan0913 在职认证  发表于 2014-5-25 16:14:46
有点类似circos图,这种属于简单的了,circos软件上简单些
曾经纯R画过,借助极坐标,然后画一圈的矩形就可以了
是什么给了你自信

报纸
zyz0329 在职认证  发表于 2014-5-25 17:04:30
yywan0913 发表于 2014-5-25 16:14
有点类似circos图,这种属于简单的了,circos软件上简单些
曾经纯R画过,借助极坐标,然后画一圈的矩形就可 ...
可以把你以前用R画的数据和代码分享下不

地板
yywan0913 在职认证  发表于 2014-5-25 18:07:50
zyz0329 发表于 2014-5-25 17:04
可以把你以前用R画的数据和代码分享下不
不知道扔哪去了   你提供数据的话,我还是能给你搞定的
是什么给了你自信

7
playmore 发表于 2014-5-28 08:34:26
zhangyangsmith 发表于 2014-5-27 18:54
A piece-by-piece solution using {graphics} only:Result:
这图画的真不错
dfPlt这个数据可以贴上来吗?谢谢
playmore邀请您访问ChinaTeX论坛!!!进入ChinaTeX论坛

8
zyz0329 在职认证  发表于 2014-5-28 19:46:27
zhangyangsmith 发表于 2014-5-25 14:49
A piece-by-piece solution using {graphics} only:Result:
可以把全部数据贴出来吗 谢谢  我在stata区也有悬赏 你可以贴在那 论坛币给你

9
zhangyangsmith 发表于 2014-5-30 06:27:04 来自手机
zyz0329 发表于 2014-5-28 19:46
可以把全部数据贴出来吗 谢谢  我在stata区也有悬赏 你可以贴在那 论坛币给你
I grabbed the data from the following link:
http://wenku.baidu.com/view/8914ed206bd97f192279e95c.html
You need to do a bit reformatting though. I simply selected the highest standard within each province as I thought the plot is just a demo...

10
zyz0329 在职认证  发表于 2014-5-31 20:26:28
zhangyangsmith 发表于 2014-5-30 06:27
I grabbed the data from the following link:
http://wenku.baidu.com/view/8914ed206bd97f192279e95c. ...
好的 但是我还是没明白啊 里面代码复制后有很多错误  可能是格式问题 但是我改不来  能不能发个txt或者word格式的运行命令附件  真的很感谢 谢谢

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-31 01:39