Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R geom_段()x轴上的不同起始值_R_Ggplot2 - Fatal编程技术网

R geom_段()x轴上的不同起始值

R geom_段()x轴上的不同起始值,r,ggplot2,R,Ggplot2,国际时间: ggplot(int_times,aes(x=-stim ,y=num,colour=gene)) + scale_y_continuous(breaks=int_times$num,labels=int_times$gene) + geom_segment(aes(xend=stim,ystart=num,yend=num),size=5) + xlab('IW (min)') + ylab('Genes') +

国际时间:

ggplot(int_times,aes(x=-stim ,y=num,colour=gene)) +
       scale_y_continuous(breaks=int_times$num,labels=int_times$gene) +
       geom_segment(aes(xend=stim,ystart=num,yend=num),size=5) +
       xlab('IW (min)') +
       ylab('Genes') +
       opts(title='multi')
这就是我现在拥有的

我希望y值'stim'从它们相应的'lag'开始,而不是从0开始

我以为你可以在geom_段的aes()中做一个xstart=lag,但这对我不起作用

有什么帮助吗?

试试这个(我在导入数据时将其命名为不同的名称):

但从你的问题来看,你的意图仍然很不清楚。您指的是开始和结束
y
值,但您的意思肯定是
x
?条形图的起始值是从传递到
ggplot
中的
x
-stim继承的。我只是通过了
lag
作为终点


如果您确实希望条形图从
lag
开始,则应从
ggplot
中删除
x=-stim
,只需在
geom\u段中传递起始值和结束值即可。(事实上,一般来说这可能是个好主意。)

xend=length(stim)
有点胡说八道。你告诉ggplot以1个元素向量的长度结束每个条,因此所有条都延伸到1(不是零,正如你的问题所暗示的)。是的,我修正了这个问题,但我不确定如何在这里合并一个起始值这是好的,我唯一改变的是xend=-lag。当我这样做时,虽然0不包括在xaxis中。像scale_x_continuous(限制(0,长度(..?)之类)这样的东西行得通吗?@Doug使用
xlim()
可能会更简单。
  gene    lag   stim  num
 Pcsk1  46.53 173.53    1
serpin2 83.00 208.02    2
  Bdnf  33.00 277.02    3
 Fosl2  49.00 266.03    4
  Pax1  33.59 243.56    5
  Acan 188.49  70.30    6
 Pthlh  50.00 271.45    7
   Crh  35.00 359.06    8
ggplot(dat,aes(x=-stim ,y=num,colour=gene)) +
       scale_y_continuous(breaks=dat$num,labels=dat$gene) +
       geom_segment(aes(xend=lag,ystart=num,yend=num),size=5) +
       xlab('IW (min)') +
       ylab('Genes') +
       opts(title='multi')