首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >网格中的格子图:更改点和x比例

网格中的格子图:更改点和x比例
EN

Stack Overflow用户
提问于 2014-06-18 04:17:01
回答 1查看 224关注 0票数 1

我正试着用格子做一个格子图,但是我不能按我希望的那样做。到目前为止,我很喜欢它的外观,我只需要一些帮助来调整它,让它看起来恰好是我想要的。我会给你我正在尝试绘制的数据,我正在使用的R代码,我得到的图形,最后是我想要制作的图形。

这是data:CSV File

  • Here is my R

代码语言:javascript
复制
Infection<-read.table("stack.csv", header=TRUE, sep=",")
attach(Infection)
head(Infection)
Infection.st<-stack(Infection[,2:13])
head(Infection.st)
Infection.st[,"gene"]<-Infection[,1]
head(Infection.st)
summary(Infection.st$ind)
Infection.st$ind<-factor(Infection.st$ind, levels=c("Disease.12h", "Control.12h", "Disease.4d", "Control.4d",
                                                    "Disease.3h", "Control.3h", "Disease.24h", "Control.24h",
                                                    "Disease.48h", "Control.48h", "Disease.72h", "Control.72h"))
summary(Infection.st$ind)

xyplot(values~ind|gene, xlab = NULL,layout=c(7,16), main="Gene Expression after infection", auto.key=list(columns = 6, cex = .8),
       pch = 21, cex = .7, scales = list(x = list(draw = FALSE)), data=Infection.st, group=ind)

3)这是我得到的图: https: //dl.dropboxusercontent.com/u/62277598/Stack.pdf (去掉冒号后面的空格)

4)最后,我想要的图形将如下所示:Desired Graph

代码语言:javascript
复制
Now I would like to get the following things in my graph as you can see in my hand made picture:

a)每个时间点使用不同的符号,但疾病是空的,对照是填充的(相同的颜色可以)。另一种选择是为每个点提供不同类型的项目,并为疾病和控制改变颜色(例如,红色和绿色)。

b)更改x轴的比例。由于它是时间序列数据,因此表示它将是很好的。然而,它并不是很精确。例如,在12小时和4天之间只有一个空间,然后在4天后空间变小。如果在每个时间点都有疾病和对照样本,那就太好了。

c)最后,如果我可以改变比例,那就太好了。有一些基因是低表达的,我只是将其绘制在一个新的图表中。我想按4天对表达进行排序,然后将基因按表达水平分组。

附言:我没有10个声誉张贴超过两个链接或图片。耽误您时间,实在对不起。

EN

回答 1

Stack Overflow用户

发布于 2014-09-18 22:59:14

我前段时间问过这个问题。以下是解决方案。我唯一没有做的事情就是改变时间点之间的距离。这实际上是不必要的。

代码语言:javascript
复制
library("latticeExtra")
library("scales")

#Command sets the working directory
setwd("/your-directory")

OR<-read.table("stack.csv", header=TRUE, sep=",")
attach(OR)
head(OR)
OR.st<-stack(OR[,2:13])
head(OR.st)
OR.st[,"gene"]<-OR[,1]
head(OR.st)
summary(OR.st$ind)
OR.st$ind<-factor(OR.st$ind, levels=c("Disease-12h", "Disease-4d", "Control-4d", "Disease-3h", "Control-3h", "Disease-24h","Control-24h", "Disease-48h", "Control-48h", "Disease-72h","Control-72h")
summary(OR.st$ind)

#comand to make symbols for each time point
supsym <- trellis.par.get("superpose.symbol")
supsym$col <- c("gold","gold","coral","coral","green","green","red","red","blueviolet","blueviolet","cornflowerblue","cornflowerblue","azure4", "azure4") #this is the line around the symbol
supsym$fill <- c("gold","gold","coral","coral","green","green","red","red","blueviolet","blueviolet","cornflowerblue","cornflowerblue","azure4", "azure4")  #this is the color to fill the symbols
supsym$pch <- c(15,19,23, 24, 15,19,15,19,15,19,15,19,15,19,15,19) #here is where you can change the type of symbol you are using
supsym$cex <- c(.8,.8,.8,.7,.8,.8,.8,.8,.8,.8,.8,.8,.8,.8,.8,.8,.8) #here you can change the size of each symbol
trellis.par.set("superpose.symbol",supsym)
colors()
options(scipen=10)
options(digits=10)

#below is just setting the color of each panel headings
bgColors <- c("gray44", "gray80", "gray44", "gray80", "gray44", 
              "gray44", "gray80", "gray44", "gray80", "gray44", 
              "gray44", "gray80", "gray44", "gray80", "gray44", 
              "gray44", "gray80", "gray44", "gray80", "gray44", 
              "gray44", "gray80", "gray44", "gray80", "gray44", 
              "gray44", "gray80", "gray44", "gray80", "gray44", 
              "gray44", "gray80", "gray44", "gray80", "gray44", 
              "gray44", "gray80", "gray44", "gray80", "gray44", 
              "gray44", "gray80", "gray44", "gray80", "gray44", 
              "gray44", "gray80", "gray44", "gray80", "gray44", 
              "gray44", "gray80", "gray44", "gray80", "gray44", 
              "gray44", "gray80", "gray44", "gray80", "gray44", 
              "gray44", "gray80", "gray44", "gray80", "gray44", 
              "gray44", "gray80", "gray44", "gray80", "gray44", 
              "gray44", "gray80", "gray44", "gray80", "gray44", 
              "gray44", "gray80", "gray44", "gray80", "gray44", 
              "gray44", "gray80", "gray44", "gray80", "gray44", 
              "gray44", "gray80", "gray44", "gray80", "gray44", 
              "gray44", "gray80", "gray44", "gray80", "gray44", 
              "gray44", "gray80", "gray44", "gray80", "gray44", 
              "gray44", "gray80", "gray44", "gray80", "gray44", 
              "gray44", "gray80", "gray44", "gray80", "gray44",
              "gray44", "gray80", "gray44", "gray80", "gray44", 
              "gray44", "gray80", "gray44", "gray80", "gray44", 
              "gray44", "gray80", "gray44", "gray80", "gray44", 
              "gray44", "gray80", "gray44", "gray80", "gray44", 
              "gray44", "gray80", "gray44", "gray80", "gray44", 
              "gray44", "gray80", "gray44", "gray80", "gray44",
              "gray44", "gray80", "gray44", "gray80", "gray44", 
              "gray44", "gray80", "gray44", "gray80", "gray44", 
              "gray44", "gray80", "gray44", "gray80", "gray44")

txtColors <- c("white", "black", "white", "black", "white",
               "white", "black", "white", "black", "white",
               "white", "black", "white", "black", "white",
               "white", "black", "white", "black", "white",
               "white", "black", "white", "black", "white",
               "white", "black", "white", "black", "white",
               "white", "black", "white", "black", "white",
               "white", "black", "white", "black", "white",
               "white", "black", "white", "black", "white",
               "white", "black", "white", "black", "white",
               "white", "black", "white", "black", "white",
               "white", "black", "white", "black", "white",
               "white", "black", "white", "black", "white",
               "white", "black", "white", "black", "white",
               "white", "black", "white", "black", "white",
               "white", "black", "white", "black", "white",
               "white", "black", "white", "black", "white",
               "white", "black", "white", "black", "white",
               "white", "black", "white", "black", "white",
               "white", "black", "white", "black", "white",
               "white", "black", "white", "black", "white",
               "white", "black", "white", "black", "white",
               "white", "black", "white", "black", "white",
               "white", "black", "white", "black", "white",
               "white", "black", "white", "black", "white",
               "white", "black", "white", "black", "white",
               "white", "black", "white", "black", "white",
               "white", "black", "white", "black", "white",
               "white", "black", "white", "black", "white",
               "white", "black", "white", "black", "white",
               "white", "black", "white", "black", "white")


# Create a function to be passes to "strip=" argument of xyplot
myStripStyle <- function(which.panel, factor.levels, ...) {
  panel.rect(0, 0, 1, 1,
             col = bgColors[which.panel],
             border = 1)
  panel.text(x = 0.5, y = 0.5,
             font=2,
             lab = factor.levels[which.panel],
             col = txtColors[which.panel])
}       



print(xyplot(values~ind|Gene,groups=ind,data=OR.st,
             layout=c(5,7),as.table=TRUE,
             type="p",
             par.strip.text=list(custBgCol=bgColors,
                                 custTxtCol=txtColors),
             strip=myStripStyle,
             auto.key=list(text=c("Disease-12h", "Disease-4d", "Control-4d", "Disease-3h",
             "Control-3h", "Disease-24h","Control-24h", "Disease-48h", "Control-48h", "Disease-72h","Control-72h"),
                           space="bottom", columns=7, pch=8, cex=.8),
             relation="same",
             #use relation="sliced", to have same scales across panels
             #scales = list(x = list(draw = FALSE),y=list(log=TRUE)),
             scales = list(x = list(draw = FALSE, abbreviate = FALSE), y = list(log = 10)),
             yscale.components = yscale.components.log10ticks,
             #aspect = "y",
             #scales=list(alternating=FALSE),
             #between=.5,#space between
             main="Gene Expression after Infection",
             #ylim=c(0,1000),#this changes the y limits
             xlab="",
             ylab=expression('RPKMs')))

如果你有任何问题,请告诉我。

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

https://stackoverflow.com/questions/24272574

复制
相关文章

相似问题

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