楼主: qianhk
4601 18

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

  • 0关注
  • 0粉丝

硕士生

4%

还不是VIP/贵宾

-

威望
0
论坛币
198 个
通用积分
0.1214
学术水平
2 点
热心指数
4 点
信用等级
2 点
经验
7736 点
帖子
52
精华
0
在线时间
156 小时
注册时间
2014-7-10
最后登录
2020-11-24

10论坛币
有没有相关学习的代码
微信截图_20170414095839.png

关键词:学习的 有没有
沙发
suzhzh 发表于 2017-4-14 10:09:59 |只看作者 |坛友微信交流群
Not sure.

使用道具

藤椅
nkunku 发表于 2017-4-15 16:08:41 |只看作者 |坛友微信交流群
持续关注

使用道具

板凳
cheetahfly 在职认证  发表于 2017-4-15 17:20:39 |只看作者 |坛友微信交流群
用ggplot2包中的geom_tile() + coord_polar()可以达到类似的效果,但细节的地方要你自己再探索尝试一下:
  1. diamonds %>%
  2.   count(color, cut) %>%
  3.   ggplot(mapping = aes(x = color, y = cut)) +
  4.   geom_tile(mapping = aes(fill = n)) +
  5.   coord_polar()
复制代码

效果如下:
polar.png

使用道具

报纸
nkunku 发表于 2017-5-5 16:48:28 |只看作者 |坛友微信交流群
ggRose能画出一个类似的图 只可惜 是类似而已

www.jpg (120.15 KB)

www.jpg

使用道具

地板
qiu435 发表于 2017-5-9 17:01:24 |只看作者 |坛友微信交流群
ggplot2 包的马赛克图,坐标设置为极坐标

使用道具

7
tmdxyz 发表于 2017-5-14 17:21:10 |只看作者 |坛友微信交流群
qiu435 发表于 2017-5-9 17:01
ggplot2 包的马赛克图,坐标设置为极坐标
ggplot(data=dat,mapping = aes(x=type,y=year,fill=death))
只可惜画不出
(1)最外头那一圈代表疾病的分类,“A,B,C...”
(2)那一圈年份不知怎么镶嵌进去
(3)中间那个空白的圆圈怎么画

polar.jpeg (311.94 KB)

polar.jpeg

zzz.rar

575 Bytes

data

本附件包括:

  • zzz.csv

使用道具

8
tmdxyz 发表于 2017-5-14 18:44:59 |只看作者 |坛友微信交流群
ggplot(data=dat,mapping=aes(x=type,y=year,fill=death))

怎么去掉中间那个圆圈里的那一个小条呀

polar.jpeg (325.49 KB)

polar.jpeg

bbb.rar

3.46 KB

data

本附件包括:

  • bbb.csv

使用道具

9
tmdxyz 发表于 2017-5-15 09:06:19 |只看作者 |坛友微信交流群
cheetahfly 发表于 2017-4-15 17:20
用ggplot2包中的geom_tile() + coord_polar()可以达到类似的效果,但细节的地方要你自己再探索尝试一下:
...
library(ggplot2)
data(diamonds)

ggplot(data=diamonds[1:100,],mapping = aes(x=color,y=cut,fill=depth))+geom_tile(mapping=aes(fill=depth))+coord_polar()

www.jpeg (76.26 KB)

www.jpeg

使用道具

10
zhangyangsmith 发表于 2017-5-24 15:52:09 |只看作者 |坛友微信交流群
An implementation using graphics only:

  1. # Get some dummy data
  2. dfDmmy <-
  3.   read.table(
  4.     text =
  5. "Influenza H5N1,A
  6. Influenza H1N1,A
  7. Influenza H7N9,A
  8. HFMD,A
  9. Mumps,B
  10. Hydatid disease,B
  11. Schistosomiasis,B
  12. Leprosy,B
  13. Brucellosis,B
  14. HIV infection,B
  15. Hepatitis E,B
  16. Hepatitis C,B
  17. Suphilis,B
  18. OID,B
  19. Cholera,C
  20. Filariasis,C
  21. Anthrax,C
  22. Leptospirosis,C
  23. ECM,C
  24. NT,C
  25. Rabies,C
  26. AD,C
  27. Typhus,C
  28. Parayphoid,C
  29. Haemorrhagic fever,C
  30. Encephalitis,C
  31. Malaria,C
  32. Tuberculosis,C
  33. Hepatitis A,C
  34. Gonorrhoea,C
  35. BD,C
  36. Pertussis,C
  37. Plague,C
  38. Diphtheria,D
  39. SARS,D
  40. Poliomyelitis,D
  41. AHC,D
  42. Dengue,D
  43. Scarlet fever,D
  44. Rubella,D
  45. Seasonal influenza,D
  46. Kala-azar,D
  47. Hepatitis B,D
  48. Measles,D",
  49.     sep = ",", header = FALSE, col.names = c("disease", "group"), as.is = TRUE
  50.         )

  51. set.seed(1705051654)

  52. dfRate <-
  53.   do.call(
  54.     "cbind",
  55.     lapply(
  56.       2004:2013,
  57.       function(i)
  58.       {
  59.     dfRes <- data.frame( runif( nrow(dfDmmy) ) )
  60.    
  61.     names(dfRes) <- sprintf("year%d", i)
  62.    
  63.     dfRes
  64.       }
  65.       )
  66.      )

  67. dfPlt <- cbind(dfDmmy, dfRate)

  68. # View(dfPlt)

  69. iNclass <- nrow(dfPlt) + 1

  70. ivYears <-
  71.   as.integer(
  72.     gsub( "year", "",  grep( "year[0-9]{4}", names(dfPlt), value = TRUE ) )
  73.         )

  74. iYearMap <- -2000L

  75. # Set plotting options
  76. par( pty = "s", mar = rep(0, times = 4) )

  77. # Start plot
  78. plot(
  79.   NA, NA, type = "n", xlim = c(-20, 20), ylim = c(-20, 20),
  80.   axes = FALSE, xlab = NA_character_, ylab = NA_character_
  81.     )

  82. # Function to convert indices to correponding angular
  83. fIndToAng <-
  84.   function(i)
  85.     return(
  86.       list(
  87.     mid = i/iNclass*2*pi,
  88.     bgn = i/iNclass*2*pi - pi/iNclass,
  89.     end = i/iNclass*2*pi + pi/iNclass
  90.       )
  91.       )

  92. # Hue of color used
  93. iHue <- rgb2hsv( col2rgb("orange") )["h", ]

  94. # Fill in data
  95. lapply(
  96.   grep( "year", names(dfPlt) ),
  97.   function(i)
  98.   {
  99.     ivY <-
  100.       as.integer(
  101.     gsub( "year", "", grep( "year", names(dfPlt)[i], value = TRUE ) )
  102.         )
  103.    
  104.     iRad <- ivY + iYearMap
  105.    
  106.     lapply(
  107.       seq.int(iNclass - 1),
  108.       function(j)
  109.       {
  110.     lAngRng <- fIndToAng(j)
  111.    
  112.     dvAng <- seq(from = lAngRng$bgn, to = lAngRng$end, length.out = 101)
  113.    
  114.     polygon(
  115.       x = c( iRad*sin(dvAng), rev( (iRad + 1)*sin(dvAng) ) ),
  116.       y = c( iRad*cos(dvAng), rev( (iRad + 1)*cos(dvAng) ) ),
  117.       border = NA, col = hsv( h = iHue, s = dfPlt[j, i], v = 1 )
  118.            )
  119.       }
  120.       )
  121.   }
  122.       )

  123. # Draw lines
  124. lapply(
  125.   seq.int(iNclass) - 1,
  126.   function(i)
  127.   {
  128.     dAng <- fIndToAng(i)$bgn
  129.    
  130.     lines(
  131.       x = ( range(ivYears + iYearMap) + c(0, 1) )*sin(dAng),
  132.       y = ( range(ivYears + iYearMap) + c(0, 1) )*cos(dAng)
  133.      )
  134.   }
  135.       )

  136. # Draw arcs - index 0 omitted for labeling
  137. lapply(
  138.   c( 0, seq_along(ivYears) ) + min(ivYears) + iYearMap,
  139.   function(i)
  140.   {
  141.     dvAng <-
  142.       seq( from = fIndToAng(0)$end, to = fIndToAng(0)$bgn + 2*pi,
  143.        length.out = (iNclass - 1)*100 + 1 )
  144.    
  145.     lines( x = i*sin(dvAng), y = i*cos(dvAng) )
  146.   }
  147.       )

  148. # Draw group
  149. with(
  150.   dfPlt,
  151.   lapply(
  152.     unique(group),
  153.     function(s)
  154.     {
  155.       ivIndx <- which(group == s)
  156.       
  157.       dvAngRng <-
  158.     c( fIndToAng( min(ivIndx) )$bgn, fIndToAng( max(ivIndx) )$end )
  159.       
  160.       dvAng <-
  161.     seq(
  162.       from = dvAngRng[1] + 2*pi/iNclass/10,
  163.       to = dvAngRng[2] - 2*pi/iNclass/10,
  164.       length.out = length(ivIndx)*100 - 2*10 + 1
  165.        )
  166.       
  167.       lines(
  168.     x =
  169.       c(
  170.         ( max(ivYears) + iYearMap + 1.1 )*sin( head(dvAng, 1) ),
  171.         ( max(ivYears) + iYearMap + 2 )*sin(dvAng),
  172.         ( max(ivYears) + iYearMap + 1.1 )*sin( tail(dvAng, 1) )
  173.        ),
  174.     y =
  175.       c(
  176.         ( max(ivYears) + iYearMap + 1.1 )*cos( head(dvAng, 1) ),
  177.         ( max(ivYears) + iYearMap + 2 )*cos(dvAng),
  178.         ( max(ivYears) + iYearMap + 1.1 )*cos( tail(dvAng, 1) )
  179.        )
  180.        )
  181.       
  182.       text(
  183.     x = ( max(ivYears) + iYearMap + 1.5 )*sin( mean(dvAngRng) ),
  184.     y = ( max(ivYears) + iYearMap + 1.5 )*cos( mean(dvAngRng) ),
  185.     label = s, adj = c(0.5, 0.5)
  186.       )
  187.     }
  188.     )
  189.     )

  190. # Write names of diseases??
  191. iNameRad <- max(ivYears) + iYearMap + 2.5

  192. with(
  193.   dfPlt,
  194.   lapply(
  195.     seq.int( length(disease) ),
  196.     function(i)
  197.     {
  198.       dTht <- fIndToAng(i)$mid
  199.       
  200.       text(
  201.     x = iNameRad*sin(dTht), y = iNameRad*cos(dTht),
  202.     labels = disease[i], # font = 2,
  203.     adj =
  204.       c(
  205.         ( 1 - sign( sin(dTht) )*
  206.         abs( sin(dTht) )^( 1/nchar( disease ) ) )/2,
  207.         ( 1 - sign( cos(dTht) )*
  208.         abs( cos(dTht) )^nchar( disease ) )/2 ),
  209.     cex = 0.75
  210.       )
  211.     }
  212.     )
  213.     )

  214. # Write years
  215. invisible(
  216.   lapply(
  217.     ivYears,
  218.     function(i)
  219.       text(
  220.     x = (i + iYearMap + 0.5)*sin( fIndToAng(0)$mid ),
  221.     y = (i + iYearMap + 0.5)*cos( fIndToAng(0)$mid ),
  222.     labels = i, adj = c(0.5, 0.5), cex = 0.75
  223.       )
  224.     )
  225.      )

  226. # Legend
  227. invisible(
  228. {
  229.   lapply(
  230.     seq(100),
  231.     function(i)
  232.       rect(
  233.     xleft = -20, ybottom = 10 + (i - 1)*0.1, xright = -18, ytop = 10 + i*0.1,
  234.     col = hsv( h = iHue, s = i/100, v = 1 ), border = NA
  235.       )
  236.     )
  237.   
  238.   rect( xleft = -20, ybottom = 10, xright = -18, ytop = 20 )
  239.   
  240.   sapply(
  241.     0:4/4,
  242.     function(d)
  243.       text( x = -18 + par("cxy")[1]*0.5, y = 10 + d*10, cex = 0.75,
  244.         labels = ifelse( d == 0, "0", sprintf("%4.2f", d) ), adj = c(0, 0.5) )
  245.     )
  246. }
  247.      )
复制代码



InfectiousDisease.png

使用道具

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

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-5-15 02:28