- 阅读权限
- 255
- 威望
- 0 级
- 论坛币
- 2445 个
- 通用积分
- 56.1531
- 学术水平
- 69 点
- 热心指数
- 78 点
- 信用等级
- 44 点
- 经验
- 4348 点
- 帖子
- 160
- 精华
- 0
- 在线时间
- 397 小时
- 注册时间
- 2008-4-14
- 最后登录
- 2020-5-7
|
An implementation using graphics only:
- # Get some dummy data
- dfDmmy <-
- read.table(
- text =
- "Influenza H5N1,A
- Influenza H1N1,A
- Influenza H7N9,A
- HFMD,A
- Mumps,B
- Hydatid disease,B
- Schistosomiasis,B
- Leprosy,B
- Brucellosis,B
- HIV infection,B
- Hepatitis E,B
- Hepatitis C,B
- Suphilis,B
- OID,B
- Cholera,C
- Filariasis,C
- Anthrax,C
- Leptospirosis,C
- ECM,C
- NT,C
- Rabies,C
- AD,C
- Typhus,C
- Parayphoid,C
- Haemorrhagic fever,C
- Encephalitis,C
- Malaria,C
- Tuberculosis,C
- Hepatitis A,C
- Gonorrhoea,C
- BD,C
- Pertussis,C
- Plague,C
- Diphtheria,D
- SARS,D
- Poliomyelitis,D
- AHC,D
- Dengue,D
- Scarlet fever,D
- Rubella,D
- Seasonal influenza,D
- Kala-azar,D
- Hepatitis B,D
- Measles,D",
- sep = ",", header = FALSE, col.names = c("disease", "group"), as.is = TRUE
- )
- set.seed(1705051654)
- dfRate <-
- do.call(
- "cbind",
- lapply(
- 2004:2013,
- function(i)
- {
- dfRes <- data.frame( runif( nrow(dfDmmy) ) )
-
- names(dfRes) <- sprintf("year%d", i)
-
- dfRes
- }
- )
- )
- dfPlt <- cbind(dfDmmy, dfRate)
- # View(dfPlt)
- iNclass <- nrow(dfPlt) + 1
- ivYears <-
- as.integer(
- gsub( "year", "", grep( "year[0-9]{4}", names(dfPlt), value = TRUE ) )
- )
- iYearMap <- -2000L
- # Set plotting options
- par( pty = "s", mar = rep(0, times = 4) )
- # Start plot
- plot(
- NA, NA, type = "n", xlim = c(-20, 20), ylim = c(-20, 20),
- axes = FALSE, xlab = NA_character_, ylab = NA_character_
- )
- # Function to convert indices to correponding angular
- fIndToAng <-
- function(i)
- return(
- list(
- mid = i/iNclass*2*pi,
- bgn = i/iNclass*2*pi - pi/iNclass,
- end = i/iNclass*2*pi + pi/iNclass
- )
- )
- # Hue of color used
- iHue <- rgb2hsv( col2rgb("orange") )["h", ]
- # Fill in data
- lapply(
- grep( "year", names(dfPlt) ),
- function(i)
- {
- ivY <-
- as.integer(
- gsub( "year", "", grep( "year", names(dfPlt)[i], value = TRUE ) )
- )
-
- iRad <- ivY + iYearMap
-
- lapply(
- seq.int(iNclass - 1),
- function(j)
- {
- lAngRng <- fIndToAng(j)
-
- dvAng <- seq(from = lAngRng$bgn, to = lAngRng$end, 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 )
- )
- }
- )
- }
- )
- # Draw lines
- lapply(
- seq.int(iNclass) - 1,
- function(i)
- {
- dAng <- fIndToAng(i)$bgn
-
- lines(
- x = ( range(ivYears + iYearMap) + c(0, 1) )*sin(dAng),
- y = ( range(ivYears + iYearMap) + c(0, 1) )*cos(dAng)
- )
- }
- )
- # Draw arcs - index 0 omitted for labeling
- lapply(
- c( 0, seq_along(ivYears) ) + min(ivYears) + iYearMap,
- function(i)
- {
- dvAng <-
- seq( from = fIndToAng(0)$end, to = fIndToAng(0)$bgn + 2*pi,
- length.out = (iNclass - 1)*100 + 1 )
-
- lines( x = i*sin(dvAng), y = i*cos(dvAng) )
- }
- )
- # Draw group
- with(
- dfPlt,
- lapply(
- unique(group),
- function(s)
- {
- ivIndx <- which(group == s)
-
- dvAngRng <-
- c( fIndToAng( min(ivIndx) )$bgn, fIndToAng( max(ivIndx) )$end )
-
- dvAng <-
- seq(
- from = dvAngRng[1] + 2*pi/iNclass/10,
- to = dvAngRng[2] - 2*pi/iNclass/10,
- length.out = length(ivIndx)*100 - 2*10 + 1
- )
-
- lines(
- x =
- c(
- ( max(ivYears) + iYearMap + 1.1 )*sin( head(dvAng, 1) ),
- ( max(ivYears) + iYearMap + 2 )*sin(dvAng),
- ( max(ivYears) + iYearMap + 1.1 )*sin( tail(dvAng, 1) )
- ),
- y =
- c(
- ( max(ivYears) + iYearMap + 1.1 )*cos( head(dvAng, 1) ),
- ( max(ivYears) + iYearMap + 2 )*cos(dvAng),
- ( max(ivYears) + iYearMap + 1.1 )*cos( tail(dvAng, 1) )
- )
- )
-
- text(
- x = ( max(ivYears) + iYearMap + 1.5 )*sin( mean(dvAngRng) ),
- y = ( max(ivYears) + iYearMap + 1.5 )*cos( mean(dvAngRng) ),
- label = s, adj = c(0.5, 0.5)
- )
- }
- )
- )
- # Write names of diseases??
- iNameRad <- max(ivYears) + iYearMap + 2.5
- with(
- dfPlt,
- lapply(
- seq.int( length(disease) ),
- function(i)
- {
- dTht <- fIndToAng(i)$mid
-
- text(
- x = iNameRad*sin(dTht), y = iNameRad*cos(dTht),
- labels = disease[i], # font = 2,
- adj =
- c(
- ( 1 - sign( sin(dTht) )*
- abs( sin(dTht) )^( 1/nchar( disease ) ) )/2,
- ( 1 - sign( cos(dTht) )*
- abs( cos(dTht) )^nchar( disease ) )/2 ),
- cex = 0.75
- )
- }
- )
- )
- # Write years
- invisible(
- lapply(
- ivYears,
- function(i)
- text(
- x = (i + iYearMap + 0.5)*sin( fIndToAng(0)$mid ),
- y = (i + iYearMap + 0.5)*cos( fIndToAng(0)$mid ),
- labels = i, adj = c(0.5, 0.5), cex = 0.75
- )
- )
- )
- # Legend
- invisible(
- {
- lapply(
- seq(100),
- function(i)
- rect(
- xleft = -20, ybottom = 10 + (i - 1)*0.1, xright = -18, ytop = 10 + i*0.1,
- col = hsv( h = iHue, s = i/100, v = 1 ), border = NA
- )
- )
-
- rect( xleft = -20, ybottom = 10, xright = -18, ytop = 20 )
-
- sapply(
- 0:4/4,
- function(d)
- text( x = -18 + par("cxy")[1]*0.5, y = 10 + d*10, cex = 0.75,
- labels = ifelse( d == 0, "0", sprintf("%4.2f", d) ), adj = c(0, 0.5) )
- )
- }
- )
复制代码
|
|