如何使用一系列位置作为输入在矩形条上生成如下所示的图形摘要。这有助于生成原理图表示。使用R或任何语言。
我尝试在互联网上搜索任何解决方案,但我找不到。
更新:
请让我知道可以执行此操作的libraries or hints
的名称。
提前谢谢。
INPUT :(未完全显示)
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
输出:
答案 0 :(得分:0)
A-mayy不是那么优雅的方式如下:
#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
(或任何内容)中提取所需尺寸来更改其尺寸: