- 阅读权限
- 255
- 威望
- 0 级
- 论坛币
- 2445 个
- 通用积分
- 56.1531
- 学术水平
- 69 点
- 热心指数
- 78 点
- 信用等级
- 44 点
- 经验
- 4348 点
- 帖子
- 160
- 精华
- 0
- 在线时间
- 397 小时
- 注册时间
- 2008-4-14
- 最后登录
- 2020-5-7
|
Quite an old post but very nice plot. I hope the functions I used below acted the same way as in 2012:
- # Data for the outer plots
- dfOuter <-
- as.data.frame(
- matrix(
- c(1, 3, 1,
- 1, 3, 2,
- 1, 3, 3,
- 1, 2, 3,
- 1, 1, 3,
- 2, 1, 3,
- 3, 1, 3,
- 3, 1, 2,
- 3, 1, 1,
- 3, 2, 1,
- 3, 3, 1,
- 2, 3, 1),
- ncol = 3, byrow = TRUE,
- dimnames = list( character(), c("B73", "F1", "Mo17") )
- )
- )
- # Dummy data for the inner plot
- set.seed(1705171415)
- n <- 100
- dfDmmy <-
- {
- ang <- runif(n = n, min = 0, max = 2*pi)
-
- rnd <- runif(100)*4
-
- data.frame( x = rnd*sin(ang), y = rnd*cos(ang) )
- }
- # Function to convert point into polar coordination and
- # classify into one of the 12 areas
- fPlr <- function(x, y)
- {
- rnd <- sqrt(x*x + y*y)
-
- ang <- acos( y/sqrt(x*x + y*y) )/pi*180*( (x >= 0)*2 - 1 ) + (x < 0)*360
- # angle between the line connecting the point and the origin and the positive
- # part of *Y* axis, in [0, 360)
-
- group <- floor(ang/30) + 1
-
- return(group)
- }
- # Function to produce outer plots
- fOutPlot <- function(dv)
- {
- # oldPar <- par(no.readonly = TRUE)
-
- # on.exit( par(oldPar) )
-
- # par( mar = c(2, 0, 0, 0), pty = "s" )
-
- dvLmt <-
- c( round( min( c( length(dv), dv ) ) ) - 1,
- round( max( c( length(dv), dv ) ) ) + 1 )
-
- plot( NA, type = "n", xlim = dvLmt, ylim = dvLmt,
- xlab = NA_character_, ylab = NA_character_,
- asp = 1, axes = FALSE, xaxs = "i", yaxs = "i")
-
- abline( h = do.call( ":", lapply(dvLmt, I) ) )
-
- abline( v = do.call( ":", lapply(dvLmt, I) ) )
-
- # axis( side = 1, at = seq_along(dv), labels = names(dv),
- # tick = FALSE, mgp = c(1, 0, 0), cex.axis = 0.8, padj = 1 )
-
- mtext( text = names(dv), side = 1, line = 0.5, cex = 2/3,
- at = seq_along(dv), adj = 0.5, padj = 0 )
-
- points( seq_along(dv), dv, type = "o", lwd = 2, pch = 16, cex = 2 )
- }
- # Map the sequnce of lines to plot
- ivSq <- c(12, 1, 2, 11, 3, 10, 4, 9, 5, 8, 7, 6)
- # Index for lines in dfOuter to plot
- iIndx <- 1L
- # Split the device
- # iNF <-
- layout(
- mat =
- matrix(
- c( 1, 1, 2, 2, 3, 4, 4, 5, 6, 6, 7, 7,
- 1, 1, 2, 2, 3, 4, 4, 5, 6, 6, 7, 7,
- 8, 8, 25, 25, 25, 25, 25, 25, 25, 25, 9, 9,
- 8, 8, 26, 26, 26, 26, 26, 26, 26, 26, 9, 9,
- 10, 10, 26, 26, 26, 26, 26, 26, 26, 26, 11, 11,
- 10, 10, 26, 26, 26, 26, 26, 26, 26, 26, 11, 11,
- 12, 12, 26, 26, 26, 26, 26, 26, 26, 26, 13, 13,
- 12, 12, 26, 26, 26, 26, 26, 26, 26, 26, 13, 13,
- 14, 14, 26, 26, 26, 26, 26, 26, 26, 26, 15, 15,
- 14, 14, 26, 26, 26, 26, 26, 26, 26, 26, 15, 15,
- 16, 16, 26, 26, 26, 26, 26, 26, 26, 26, 17, 17,
- 16, 16, 19, 19, 20, 21, 21, 22, 23, 23, 17, 17,
- 18, 18, 19, 19, 20, 21, 21, 22, 23, 23, 24, 24
- ),
- ncol = 12, byrow = TRUE
- )
- )
- # layout.show(iNF)
- # Decrease margin size
- oldPar <- par(no.readonly = TRUE)
-
- on.exit( par(oldPar) )
- par( mar = c(2, 0, 0, 0), pty = "s" )
- # Area 1
- plot.new()
- # Area 2
- # plot.new()
- fOutPlot( unlist( dfOuter[ ivSq[iIndx], ] ) )
- if( iIndx < nrow(dfOuter) ) iIndx <- iIndx + 1L
- # Area 3
- plot.new()
- # Area 4
- # plot.new()
- fOutPlot( unlist( dfOuter[ ivSq[iIndx], ] ) )
- if( iIndx < nrow(dfOuter) ) iIndx <- iIndx + 1L
- # Area 5
- plot.new()
- # Area 6
- # plot.new()
- fOutPlot( unlist( dfOuter[ ivSq[iIndx], ] ) )
- if( iIndx < nrow(dfOuter) ) iIndx <- iIndx + 1L
- # Area 7
- plot.new()
- # Area 8
- # plot.new()
- fOutPlot( unlist( dfOuter[ ivSq[iIndx], ] ) )
- if( iIndx < nrow(dfOuter) ) iIndx <- iIndx + 1L
- # Area 9
- # plot.new()
- fOutPlot( unlist( dfOuter[ ivSq[iIndx], ] ) )
- if( iIndx < nrow(dfOuter) ) iIndx <- iIndx + 1L
- # Area 10
- plot.new()
- # Area 11
- plot.new()
- # Area 12
- # plot.new()
- fOutPlot( unlist( dfOuter[ ivSq[iIndx], ] ) )
- if( iIndx < nrow(dfOuter) ) iIndx <- iIndx + 1L
- # Area 13
- # plot.new()
- fOutPlot( unlist( dfOuter[ ivSq[iIndx], ] ) )
- if( iIndx < nrow(dfOuter) ) iIndx <- iIndx + 1L
- # Area 14
- plot.new()
- # Area 15
- plot.new()
- # Area 16
- # plot.new()
- fOutPlot( unlist( dfOuter[ ivSq[iIndx], ] ) )
- if( iIndx < nrow(dfOuter) ) iIndx <- iIndx + 1L
- # Area 17
- # plot.new()
- fOutPlot( unlist( dfOuter[ ivSq[iIndx], ] ) )
- if( iIndx < nrow(dfOuter) ) iIndx <- iIndx + 1L
- # Area 18
- plot.new()
- # Area 19
- # plot.new()
- fOutPlot( unlist( dfOuter[ ivSq[iIndx], ] ) )
- if( iIndx < nrow(dfOuter) ) iIndx <- iIndx + 1L
- # Area 20
- plot.new()
- # Area 21
- # plot.new()
- fOutPlot( unlist( dfOuter[ ivSq[iIndx], ] ) )
- if( iIndx < nrow(dfOuter) ) iIndx <- iIndx + 1L
- # Area 22
- plot.new()
- # Area 23
- # plot.new()
- fOutPlot( unlist( dfOuter[ ivSq[iIndx], ] ) )
- if( iIndx < nrow(dfOuter) ) iIndx <- iIndx + 1L
- # Area 24
- plot.new()
- # Area 25
- # plot.new()
- par(pty = "m")
- plot(
- NA, type = "n", xlim = c(0, 1), ylim = c(0, 1),
- xlab = NA_character_, ylab = NA_character_, axes = FALSE
- )
- text(
- x = mean( par("usr")[1:2] ), y = mean( par("usr")[3:4] ),
- labels = "2D presentation of 3-line mean pattern",
- cex = par("cex.main"), font = par("font.main"), xpd = TRUE
- )
- # Area 26
- # plot.new()
- par(pty = "s")
- plot(
- NA, type = "n", xlim = c(-4, 4), ylim = c(-4, 4), xaxs = "r", yaxs = "r",
- xlab = NA_character_, ylab = NA_character_, axes = F
- )
- box()
- # Reference lines
- invisible(
- lapply(
- seq.int(3) - 1,
- function(i)
- {
- ang <- i/3*pi
-
- lines( x = c(-4, 4)*cos(ang), y = c(-4, 4)*sin(ang), lty = 1 )
- }
- )
- )
- invisible(
- lapply(
- seq.int(3) - 1,
- function(i)
- {
- ang <- i/3*pi + pi/6
-
- lines( x = c(-4, 4)*cos(ang), y = c(-4, 4)*sin(ang), lty = 8 )
- }
- )
- )
- # Reference circles
- invisible(
- lapply(
- seq.int(4),
- function(i)
- {
- ang <- seq.int(360)
-
- # points( i*cos(ang/180*pi), i*sin(ang/180*pi), pch = ".",
- # cex = 1, col = "#BFBFBF" )
-
- lines( i*cos(ang/180*pi), i*sin(ang/180*pi), lty = "14",
- col = "#BFBFBF" )
- }
- )
- )
- # Text for each reference line
- svText <-
- do.call(
- "c",
- lapply(
- seq( nrow(dfOuter) ),
- function(i)
- {
- ivOdr <- order( unlist( dfOuter[i, ] ) )
- paste0(
- do.call(
- "paste0",
- lapply(
- seq.int( length(ivOdr) - 1 ),
- function(j)
- paste0(
- names(dfOuter)[ ivOdr[j] ],
- ifelse(
- dfOuter[ i, ivOdr[j] ] == dfOuter[ i, ivOdr[j + 1] ],
- "=", "<"
- )
- )
- )
- ),
- names(dfOuter)[ tail(ivOdr, 1) ]
- )
- }
- )
- )
- invisible(
- lapply(
- seq_along(svText),
- function(i)
- {
- rnd <- 4L
-
- ang <- (i - 1)*pi/6
-
- dX <- rnd*cos(ang)
-
- dY <- rnd*sin(ang)
-
- # Enough space to the border?
- bdr <-
- abs( dX + sign(dX)*( strwidth(svText) + par("cxy")[1] ) ) >
- max( abs( par("usr")[1:2] ) )
-
- text(
- x =
- ifelse(
- bdr,
- ifelse( dX > 0, par("usr")[2] - par("cxy")[1],
- par("usr")[1] + par("cxy")[1] ),
- dX
- ),
- y = dY + ifelse( dY > 0, par("cxy")[2]/2, -1*par("cxy")[2]/2 ),
- labels = svText[i],
- adj =
- c( ifelse( bdr, as.integer(dX > 0), 0.5 ), ifelse(dY > 0, 0, 1) )
- )
- }
- )
- )
- # Number for each region
- invisible(
- lapply(
- seq.int(12),
- function(i)
- {
- ang <- (i/6 - 1/12)*pi
-
- rnd <-
- min(
- abs(
- c( 4.5,
- (par("usr")[1:2] + c(1, -1)*par("cxy")[1])/sin(ang),
- (par("usr")[3:4] + c(1, -1)*par("cxy")[2])/cos(ang) )
- )
- )
-
- text( x = rnd*sin(ang), y = rnd*cos(ang),
- labels = as.character(i), adj = c(0.5, 0.5) )
- }
- )
- )
- # Finally add the points
- with( dfDmmy, points( x, y, pch = 20, col = rainbow(12)[ fPlr(x, y) ] ) )
复制代码
Output:
|
|