楼主: qianhk
5517 18

[程序分享] 请问这张图是用R哪个包画出来的? [推广有奖]

11
tmdxyz 发表于 2017-5-24 17:19:02
zhangyangsmith 发表于 2017-5-24 15:52
An implementation using graphics only:
谢谢!可是代码在运行到如下行时,就提示出错了
Error in seq(from = lAngRngbgn, to = lAngRngbgn, to = lAngRngend, length.out = 101) :
  object 'lAngRngbgn' not found


# Fill in data

lapply(
  grep( "year", names(dfPlt) ),
  function(i)
  {
    ivY <-
      as.integer(
    gsub( "year", "", grep( "year", names(dfPlt), value = TRUE ) )
        )

    iRad <- ivY + iYearMap
   
    lapply(
      seq.int(iNclass - 1),
      function(j)
      {
    lAngRng <- fIndToAng(j)
   
    dvAng <- seq(from = lAngRngbgn,to=lAngRngbgn, to = lAngRngend, length.out = 101)
   
    polygon(
      x = c( iRad*sin(dvAng), rev( (iRad + 1)*sin(dvAng) ) ),
      y = c( iRad*cos(dvAng), rev( (iRad + 1)*cos(dvAng) ) ),
      border = NA, col = hsv( h = iHue, s = dfPlt[j, i], v = 1 )
           )
      }
      )
  }
      )
最后的图形是这样的

zaq.jpg (226.54 KB)

zaq.jpg

12
zhangyangsmith 发表于 2017-5-24 20:35:50
tmdxyz 发表于 2017-5-24 17:19
谢谢!可是代码在运行到如下行时,就提示出错了
Error in seq(from = lAngRngbgn, to = lAngRngbgn, to  ...
What kind of error did you get? Can you please make sure you have the exact same structure of the dataset as I do:
  1. head(dfPlt)
  2. ##           disease group  year2004  year2005  year2006  year2007   year2008  year2009
  3. ## 1  Influenza H5N1     A 0.9577311 0.3965613 0.1890113 0.8545589 0.53261816 0.6567532
  4. ## 2  Influenza H1N1     A 0.5338605 0.8023693 0.7815694 0.5960275 0.22160178 0.9374999
  5. ## 3  Influenza H7N9     A 0.1341294 0.7764125 0.2490056 0.3516824 0.18324296 0.3640789
  6. ## 4            HFMD     A 0.6588914 0.8381510 0.9168572 0.2359513 0.01746788 0.4080601
  7. ## 5           Mumps     B 0.2842338 0.9626250 0.7916511 0.6583149 0.93995698 0.1822337
  8. ## 6 Hydatid disease     B 0.4790436 0.3142137 0.3427979 0.7613149 0.36686015 0.5481724
  9. ##    year2010  year2011  year2012   year2013
  10. ## 1 0.9294423 0.4513942 0.7816525 0.18922903
  11. ## 2 0.4824861 0.1420006 0.6364044 0.07943281
  12. ## 3 0.2641812 0.8124257 0.3817600 0.10299040
  13. ## 4 0.6910557 0.4500182 0.2540463 0.33690278
  14. ## 5 0.7595545 0.5402687 0.1850836 0.49937368
  15. ## 6 0.9206673 0.4103495 0.1417597 0.43828254
复制代码

13
tmdxyz 发表于 2017-5-25 06:28:06
zhangyangsmith 发表于 2017-5-24 20:35
What kind of error did you get? Can you please make sure you have the exact same structure of the  ...
在运行程序的前面一些代码时,没有问题,也得得到像您所说的正确的数据dfPlt,见附图。
继续往下执行,直到下面这段语句
# Fill in data
# Fill in data
lapply(
  grep( "year", names(dfPlt) ),
  function(i)
  {
    ivY <-
      as.integer(
    gsub( "year", "", grep( "year", names(dfPlt), value = TRUE ) )
        )
   
    iRad <- ivY + iYearMap
   
    lapply(
      seq.int(iNclass - 1),
      function(j)
      {
    lAngRng <- fIndToAng(j)
   
    dvAng <- seq(from = lAngRngbgn,to=lAngRngbgn, to = lAngRngend, length.out = 101)
   
    polygon(
      x = c( iRad*sin(dvAng), rev( (iRad + 1)*sin(dvAng) ) ),
      y = c( iRad*cos(dvAng), rev( (iRad + 1)*cos(dvAng) ) ),
      border = NA, col = hsv( h = iHue, s = dfPlt[j, i], v = 1 )
           )
      }
      )
  }
      )

就开始出现错误提示:
Error in seq(from = lAngRngbgn, to = lAngRngbgn, to = lAngRngend, length.out = 101) :
  object 'lAngRngbgn' not found

难道有可能是您的代码在网页中显示不当吗?请看截图



cxz.jpg (499.18 KB)

cxz.jpg

rew.jpg (19.84 KB)

rew.jpg

head.jpg (234.54 KB)

head.jpg

14
tmdxyz 发表于 2017-5-30 07:23:06
zhangyangsmith 发表于 2017-5-24 15:52
An implementation using graphics only:
可能是网页在显示代码方面的瑕疵,我仔细核对了一下可能出错的地方,代码见附件。可是依然得不到与你一样的图形。请问,问题究竟在哪里呢?

您能不能把您的回帖中的代码另存为文本文件或R文件,然后放出来供大家学习?

Rplot.png (93.81 KB)

Rplot.png

Rplot.rar
下载链接: https://bbs.pinggu.org/a-2261497.html

1.89 KB

本附件包括:

  • Rplot.R

Rplot.pdf

784.35 KB

15
tmdxyz 发表于 2017-5-30 09:10:55
zhangyangsmith 发表于 2017-5-24 15:52
An implementation using graphics only:
刚才又试了一下,看起来,在复制他的代码的时候(除了网页显示的代码有瑕疵外),之所以不能出来与你一样的图形,问题主要出在# Fill in data以及# Write names of diseases这两段语句里。我把它们挪到最后,运行其余所以全部语句,只留下这两段语句不运行,就能得到以下图形。

www.jpg (150.15 KB)

www.jpg

两个关键的语句.rar

2.09 KB

本附件包括:

  • 两个关键的语句.r

16
zhangyangsmith 发表于 2017-6-1 17:33:29
tmdxyz 发表于 2017-5-30 09:10
刚才又试了一下,看起来,在复制他的代码的时候(除了网页显示的代码有瑕疵外),之所以不能出来与你一样 ...
The original codes have been edited. There are two indices missed in the codes. I have no clue why this happened as they did exist in my local version of the scripts.

polarCoordinates.R.txt (5.05 KB)

17
peterlovejin 发表于 2017-6-1 22:30:10
果然, 有很多大神存在~~

18
tmdxyz 发表于 2017-6-2 04:55:19
zhangyangsmith 发表于 2017-6-1 17:33
The original codes have been edited. There are two indices missed in the codes. I have no clue why ...
非常感谢!这回已经没有任何问题了。

19
zhangyangsmith 发表于 2017-6-2 14:47:52
*****xyz 发表于 2017-6-2 04:55
非常感谢!这回已经没有任何问题了。
Enjoy the codes.

pinggu-plots.R.txt (22.53 KB, 需要: 500 个论坛币)

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

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