English 中文(简体)
ggplot: Lineplot of means of two groups
原标题:ggplot: lineplot of means of two groups

我在座椅上搜寻并搜索了回答我的问题;。 这份“文件处理我的问题,但我未能对法典进行修改,以确定我的图表。

我有数据,以长期格式重塑,如:

ID          Var1      GenePosition   ContinuousOutcomeVar
1           control      X20068492 0.092813611
2           control      X20068492 0.001746708
3           case         X20068492 0.069251157
4           case         X20068492 0.003639304

每张<代码>ID每个职位都有一个数值<代码>ContinuousOutcomeVar,有86个职位和10个身份证。 我想根据X轴线和轴线连续结果变量的定位线图。 我想有两个组:一个案件组和控制组,因此每个职位都应有两点:一个是案件的平均价值,另一个是控制的平均价值。 然后我想一条连接案件的线,一条连接控制线。 我知道这一点是容易的,但我对R来说是新鲜的——我在那里工作了8个小时,我可以这样做。 以下是我的看法;我确实赞赏一些见解。 如果在摇篮中存在这种情况,我真的抱歉......。 我真诚地审视了所有问题,并试图修改许多法典,但是仍然 t着。

My code: This code plots all the values for all IDs at each position, and connects them for the two groups. It gives me a black dot at the mean of all 10 values per position (I think):

lineplot <- ggplot(data=seq.long, aes(x=Position, y=PMethyl, 
    group=CACO, colour=CACO)) +
    stat_summary (fun.y=mean, geom="point", aes(group=1), color="black") +      
    geom_line() + geom_point()

我可以拿R到,不划出所有10点;只有两个手段(每个案件/控制小组一个),每个职位都有案件和营地;控制每个轴线连接的数值。

最佳回答

首先,调整了原样本数据,以包含一个以上独特的<密码>。

dput(seq.long)
structure(list(ID = 1:8, Var1 = structure(c(2L, 2L, 1L, 1L, 2L, 
2L, 1L, 1L), .Label = c("case", "control"), class = "factor"), 
    GenePosition = structure(c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L
    ), .Label = c("X20068492", "X20068493"), class = "factor"), 
    ContinuousOutcomeVar = c(0.092813611, 0.001746708, 0.069251157, 
    0.003639304, 0.112813611, 0.002746708, 0.089251157, 0.004639304
    )), .Names = c("ID", "Var1", "GenePosition", "ContinuousOutcomeVar"
), class = "data.frame", row.names = c(NA, -8L))

如果你只是想代表每一条<代码>GenePosition和Var1的组合值,那么在进行绘图之前计算平均值将比较容易。 可通过以下功能实现:<代码>dply(>,从图书馆<代码>plyr/code>。

library(plyr)    
seq.long.sum<-ddply(seq.long,.(Var1,GenePosition),
       summarize, value = mean(ContinuousOutcomeVar))
seq.long.sum
     Var1 GenePosition      value
1    case    X20068492 0.03644523
2    case    X20068493 0.04694523
3 control    X20068492 0.04728016
4 control    X20068493 0.05778016

现在,有了这一新的数据框架,你才必须给出<条码>x<>/条码>和<条码>。 应在<代码>colour=和group=中加以使用,以确保每个群体有不同的肤色,并且有线上的联系。

ggplot(seq.long.sum,aes(x=GenePosition,y=value,colour=Var1,group=Var1))+
   geom_point()+geom_line()

“entergraph

问题回答




相关问题
How to plot fitted model over observed time series

This is a really really simple question to which I seem to be entirely unable to get a solution. I would like to do a scatter plot of an observed time series in R, and over this I want to plot the ...

REvolution for R

since the latest Ubuntu release (karmic koala), I noticed that the internal R package advertises on start-up the REvolution package. It seems to be a library collection for high-performance matrix ...

R - capturing elements of R output into text files

I am trying to run an analysis by invoking R through the command line as follows: R --no-save < SampleProgram.R > SampleProgram.opt For example, consider the simple R program below: mydata =...

R statistical package: wrapping GOFrame objects

I m trying to generate GOFrame objects to generate a gene ontology mapping in R for unsupported organisms (see http://www.bioconductor.org/packages/release/bioc/vignettes/GOstats/inst/doc/...

Changing the order of dodged bars in ggplot2 barplot

I have a dataframe df.all and I m plotting it in a bar plot with ggplot2 using the code below. I d like to make it so that the order of the dodged bars is flipped. That is, so that the bars labeled "...

Strange error when using sparse matrices and glmnet

I m getting a weird error when training a glmnet regression. invalid class "dgCMatrix" object: length(Dimnames[[2]]) must match Dim[2] It only happens occasionally, and perhaps only under larger ...

Generating non-duplicate combination pairs in R

Sorry for the non-descriptive title but I don t know whether there s a word for what I m trying to achieve. Let s assume that I have a list of names of different classes like c( 1 , 2 , 3 , 4 ) ...

Per panel smoothing in ggplot2

I m plotting a group of curves, using facet in ggplot2. I d like to have a smoother applied to plots where there are enough points to smooth, but not on plots with very few points. In particular I d ...

热门标签