简体   繁体   English

在R中获取连续线图

[英]Get continuous line plot in R

I'd like to plot something like the image attached.我想绘制类似于所附图像的东西。 It come from this paper http://www.nature.com/nature/journal/v488/n7410/extref/nature11319-s1.pdf (Figure 11D).它来自这篇论文http://www.nature.com/nature/journal/v488/n7410/extref/nature11319-s1.pdf (图 11D)。 I know it was done in R, but I don't know the package/function.我知道它是在 R 中完成的,但我不知道包/功能。

This is a subset of my data:这是我的数据的一个子集:

SampleID prevo.bact
37.TO.O -3.00468736
31.TO.V -3.42291741
06.BO.VG -2.56462361
37.PR.O  0.91296148
03.BA.O  0.02868464
30.BO.V -0.24479930

I ordered the values in crescent way and I tried to plot them using plot我以新月的方式订购了这些值,并尝试使用 plot 绘制它们

mydata.ordered=order(my.data$prevo.bact) 
plot(my.data$prevo.bact[my.data.ordered])

This is quite close to the output I'd like to get, but I don't know how to change the points obtaining the vertical lines (no one of the types available in plot is like that) and how to change the color according to a class vector clD这与我想要获得的输出非常接近,但我不知道如何更改获得垂直线的点(绘图中没有一种可用的类型是这样的)以及如何根据类向量clD

clD = unlist(lapply(strsplit(row.names(my.data),'[.]'),function(x){x[[3]]}))
names(clD)=row.names(my.data)

Moreover, I don't want empty space between the points (like in the picture attached, I'd like a continuum).此外,我不想要点之间的空白空间(如附图所示,我想要一个连续体)。 How can I get something similar?我怎样才能得到类似的东西? Probably the basic plot is not the way...可能基本情节不是这样的......

Thanks Francesca谢谢弗朗西斯卡

我想得到的例子

在此处输入图像描述

I give it a try.我试一试。 I think the reason that the plot looks continuous is simply that there are enough points to create the illusion of continuity.我认为情节看起来连续的原因只是有足够的点来创造连续性的错觉。 In order to have enough points, I had to create some sample data myself, because the six points you give are not enough.为了有足够的分数,我不得不自己创建一些样本数据,因为你给的六个分数是不够的。

library(ggplot2)
my.data <- data.frame(SampleID=rep(c("37.TO.O","31.TO.V","06.BO.VG","37.PR.O","03.BA.O","30.BO.V"),times=30),
                  prevo.bact=rnorm(180,0,3),
                  stringsAsFactors=FALSE)
my.data$clD <- sapply(strsplit(my.data$SampleID,'[.]'),function(x){x[[3]]})
my.data.ordered <- my.data[order(my.data$prevo.bact),]
my.data.ordered$num <- 1:nrow(my.data)
ggplot(my.data.ordered,aes(num,prevo.bact)) + geom_point(size=5,shape="|",aes(col=clD)) + theme_classic()

I have used ggplot because I wouldn't know how to colour the data points using base graphics.我使用 ggplot 是因为我不知道如何使用基本图形为数据点着色。 The option shape="|"选项shape="|" uses vertical lines instead of points.使用垂直线而不是点。

This is the figure I get:这是我得到的数字:在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM