首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用R和轴断开符()绘制相当复杂的图表

使用R和轴断开符()绘制相当复杂的图表
EN

Stack Overflow用户
提问于 2012-02-09 07:10:08
回答 1查看 996关注 0票数 1

我有一个由4563个蛋白质氨基酸组成的数据集。用三种不同的处理方法和两种不同的氧化剂,对该蛋白质中的氨基酸进行氧化。我想在治疗的基础上在图表中画出这些氧化的位置。不同的线条尺寸代表不同的氧化剂浓度,线条类型(虚线和实线)代表不同类型的氧化剂。我想在每1000个氨基酸上打破轴心。我已经用excel和gimp创建了一个类似的模板(这相当耗时,而且可能不合适!)。模板中的0.33是行高。http://dl.dropbox.com/u/58221687/Chakraborty_Figure1.png。下面是数据集:http://dl.dropbox.com/u/58221687/AA-Position-template.xls

提前谢谢。Sourav

EN

回答 1

Stack Overflow用户

发布于 2012-02-09 20:18:19

我将在基础图形中做到这一点,尽管我相信其他人可以在晶格或ggplot2中做同样或更好的事情。我认为你需要做的最主要的事情就是对你的数据进行重塑,并重新思考数据需要什么样的格式才能进行绘图。如果1)数据是长格式的,2)颜色、线型、宽度等变量作为额外的列可用,我就会用你的数据做这件事。如果您有这样的数据,那么您可以将其减少到只包括需要绘制线段的氨基酸。我已经模拟了一个与您的数据集类似的数据集。您应该能够修改此代码以适合您的情况:首先是数据集:

代码语言:javascript
复制
    set.seed(1)
    # make data.frame just with info for the lines you'll actually draw
    # your data was mostly zeros, no need for those lines
    position <- sort(sample(1:4563,45,replace = FALSE))
    # but the x position needs to be shaved down!
    # modulars are the real x positions on the plot:
    xpos <- position%%600
    # line direction appeared in your example but not in your text
    posorneg <- sample(c(-1,1),45,replace = TRUE,prob=c(.05,.95))
    # oxidant concentration for line width- just rescale the oxidant concentration
    # values you have to fall between say .5 and 3, or whatever is nice and visible
    oxconc   <- (.5+runif(45))^2
    # oxidant type determines line type- you mention 2
    # just assign these types to lines types (integers in R)
    oxitype  <- sample(c(1,2),45,replace = TRUE) 
    # let's say there's another dimension you want to map color to
    # in your example png, but not in your description.
    color <- sample(c("green","black","blue"),45,replace=TRUE)

    # and finally, which level does each segment need to belong to?
    # you have 8 line levels in your example png. This works, might take
    # some staring though:
    level <- 0
    for (i in 0:7){
    level[position %in% ((i*600):(i*600+599))] <- 8-i
    }

    # now stick into data.drame:
    AminoData <-data.frame(position = position, xpos = xpos, posorneg = posorneg, 
         oxconc = oxconc, oxitype = oxitype, level = level, color = color)

好的,想象一下你可以把你的数据简化成这样简单的东西。绘图的主要工具(在base中)将是segments()。它是矢量化的,所以不需要循环或花哨的东西:

代码语言:javascript
复制
    # now we draw the base plot:
    par(mar=c(3,3,3,3))
    plot(NULL, type = "n", axes = FALSE, xlab = "", ylab = "", 
         ylim =  c(0,9), xlim = c(-10,609))
    # horizontal segments:
    segments(0,1:8,599,1:8,gray(.5))
    # some ticks: (also not pretty)
    segments(rep(c((0:5)*100,599),8), rep(1:8,each=7)-.05, rep(c((0:5)*100,599),8), 
       rep(1:8,each=7)+.05, col=gray(.5))
    # label endpoints:
    text(rep(10,8)+.2,1:8-.2,(7:0)*600,pos=2,cex=.8)
    text(rep(589,8)+.2,1:8-.2,(7:0)*600+599,pos=4,cex=.8)
    # now the amino line segments, remember segments() is vectorized
    segments(AminoData$xpos, AminoData$level, AminoData$xpos, 
       AminoData$level + .5 * AminoData$posorneg, lty = AminoData$oxitype, 
       lwd = AminoData$oxconc, col = as.character(AminoData$color))
    title("mostly you just need to reshape and prepare\nyour data to do this easily in base")

对于一些人来说,这可能太手工了,但这是我处理特殊情节的方式。

票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9202998

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档