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

使用R和轴中断()绘制相当复杂的图表,r,plot,ggplot2,lattice,R,Plot,Ggplot2,Lattice,Hi R用户和程序员, 我有一个由4563个蛋白质氨基酸组成的数据集。使用三种不同的处理和两种不同的氧化剂,该蛋白质中的氨基酸被氧化。我想根据处理方法在图表中标出这些氧化作用的位置。不同的线条尺寸将代表不同的氧化剂浓度,虚线和实线类型将代表不同类型的氧化剂。我想把每1000个氨基酸的轴打断。 我用excel和gimp创建了一个类似的模板,这非常耗时,而且可能不合适!。模板中的0.33表示线条高度。 . 以下是数据集: 提前谢谢。 苏拉夫我将在基本图形中这样做,不过我相信其他人也可以在latti

Hi R用户和程序员, 我有一个由4563个蛋白质氨基酸组成的数据集。使用三种不同的处理和两种不同的氧化剂,该蛋白质中的氨基酸被氧化。我想根据处理方法在图表中标出这些氧化作用的位置。不同的线条尺寸将代表不同的氧化剂浓度,虚线和实线类型将代表不同类型的氧化剂。我想把每1000个氨基酸的轴打断。 我用excel和gimp创建了一个类似的模板,这非常耗时,而且可能不合适!。模板中的0.33表示线条高度。 . 以下是数据集:

提前谢谢。
苏拉夫

我将在基本图形中这样做,不过我相信其他人也可以在lattice或ggplot2中这样做,甚至做得更好。我认为你需要做的最主要的事情是,用你的数据轻松地绘制出这样的图,重塑并重新思考数据需要采用什么格式才能适合绘制。如果1是长格式的数据,2是基础颜色、线型、宽度等的变量可以作为额外的列使用,我会使用您的数据来完成这项工作。如果你有这样的数据,那么你可以把它减少到只包括需要画线段的氨基酸。我模拟了一个类似于你的数据集。您应该能够修改此代码以适合您的情况: 首先是数据集:

    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)

对于某些人来说,这可能过于手工,但这是我进行特殊绘图的方式。

我将在基本图形中进行此操作,尽管我相信其他人也可以在lattice或ggplot2中进行相同或更好的操作。我认为你需要做的最主要的事情是,用你的数据轻松地绘制出这样的图,重塑并重新思考数据需要采用什么格式才能适合绘制。如果1是长格式的数据,2是基础颜色、线型、宽度等的变量可以作为额外的列使用,我会使用您的数据来完成这项工作。如果你有这样的数据,那么你可以把它减少到只包括需要画线段的氨基酸。我模拟了一个类似于你的数据集。您应该能够修改此代码以适合您的情况: 首先是数据集:

    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)

对于某些人来说,这可能过于手工,但这是我进行特殊绘图的方式。

如果您可以提供一个虚拟数据集,包括您希望用于计算线条尺寸、线条厚度/宽度的氧化剂浓度值、氧化剂类型和处理,这可能会很有用。根据处理情况绘制氧化位置的含义有点不清楚。在您所附的图中,对应的变化“位置”是什么?你指的是向上线还是向下线?也不清楚你所说的尺寸是什么意思。行高或行宽都可以称为行大小。@Jbaums:你说得对,我在发布问题后正在考虑一个虚拟数据集。实验中使用的氧化剂A和B的浓度分别为10微米、100微米和1000微米。行大小不是一个合适的词,我以前用过。线条尺寸应替换为线条高度。我不会改变宽度,因为它可能会干扰数据表示,例如AA503可能被氧化100微米,504可能被氧化1000微米。下行线间接氧化不再是我主要关心的问题,因为氧化剂a和B只跟在直接氧化后面。@Dwin:很抱歉这个非特定术语。我希望现在更清楚。如果您可以提供一个虚拟数据集,包括您希望用于计算线条尺寸、线条厚度/宽度?的氧化剂浓度值、氧化剂类型和处理方法,这可能会很有用。根据处理情况绘制氧化位置的含义有点不清楚。在您所附的图中,对应的变化“位置”是什么?你指的是向上线还是向下线?也不清楚你所说的尺寸是什么意思。行高或行宽都可以称为行大小。@Jbaums:你说得对,我在发布问题后正在考虑一个虚拟数据集。实验中使用的氧化剂A和B的浓度分别为10微米、100微米和1000微米。行大小不是一个合适的词,我以前用过。线条尺寸应替换为线条高度。我不会改变宽度,因为它可能会干扰数据表示,例如AA503可能被氧化100微米,504可能被氧化1000微米。下行线间接氧化不再是我主要关心的问题,因为氧化剂a和B只跟在直接氧化后面。@Dwin:很抱歉这个非特定术语。我希望现在更清楚。我真的很感谢你的及时回复。这正是我想要的。非常感谢!!感谢您重新组织数据、代码和详细解释。我会根据需要修改它,如果我遇到一些我认为不会发生的重大问题,我会给你回复。我非常感谢你的及时回复。这是 正是我想要的。非常感谢!!感谢您重新组织数据、代码和详细解释。我会根据需要修改它,如果我遇到一些我认为不会发生的重大问题,我会给你回复。