0

如何使用一系列位置作为输入在矩形条上生成如下所示的图形摘要。这有助于生成示意图表示。使用 R 或任何语言。

我尝试在互联网上搜索任何解决方案,但没有找到。

更新:请让我知道libraries or hints可以执行此操作的名称。提前致谢。

输入:(未完全显示)

Helix   56 – 59         
Helix   62 – 78         
Helix   80 – 89         
Helix   95 – 102
//
Beta strand 175 – 178           
Beta strand 184 – 186       
Helix       188 – 190           
Beta strand 194 – 198       
Turn        199 – 202   

输出:
在此处输入图像描述

4

1 回答 1

0

一种可能不那么优雅的方式如下:

#random data
DF <- data.frame(range = c("10 - 20", "28 - 30", "3 - 8", 
                          "100 - 180", "185 - 190", "200 - 350"), 
                    type = rep(c("helix", "beta", "turn"), 2), stringsAsFactors = F)

#manipulate "from - to" numerically
newDF <- cbind(DF, do.call(rbind, strsplit(DF$range, " - ")), stringsAsFactors = F)
names(newDF) <- c(names(DF), "xleft", "xright") #name the columns
newDF$"xleft" <- as.numeric(newDF$"xleft")  #make the values numeric
newDF$"xright" <- as.numeric(newDF$"xright") # -//-

#> newDF
#      range  type xleft xright
#1   10 - 20 helix    10     20
#2   28 - 30  beta    28     30
#3     3 - 8  turn     3      8
#4 100 - 180 helix   100    180
#5 185 - 190  beta   185    190
#6 200 - 350  turn   200    350

#color for each type
colors. <- c(rgb(0,1,0,1/3), rgb(0,0,1,1/3), rgb(1,0,0,1/3))[as.factor(newDF$type)]

#background plot 
plot(NULL, xlim = c(0, max(newDF[c("xleft", "xright")])), 
                        ylim = c(0,1), yaxt = "n", ann = F)

#legend
legend(x = max(newDF[c("xleft", "xright")]) * 0.5, y = 1.15, xpd = T, ncol = 3, 
         legend = c("beta", "helix", "turn"), 
             fill = c(rgb(0,1,0,1/3), rgb(0,0,1,1/3), rgb(1,0,0,1/3)))

#function that draws rectangles for each range
fun <- function(xl, yb, xr, yt, col.)
{
 rect(xleft = xl, ybottom = yb, xright = xr, ytop = yt, col = col.)
} 

#draw all rectangles
mapply(fun, xl = newDF$xleft, xr = newDF$xright, col. = colors., 
                       MoreArgs = list(yb = 0, yt = 1))

该图绘制成方形,但您可以通过拖动其框或将其提取到jpeg具有所需尺寸的(或任何东西)中来更改其尺寸:

类似矩形的情节

于 2013-10-30T10:58:04.847 回答