Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/rust/4.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 ggplot2 x轴上的双标签_R_Ggplot2_Axis Labels - Fatal编程技术网

R ggplot2 x轴上的双标签

R ggplot2 x轴上的双标签,r,ggplot2,axis-labels,R,Ggplot2,Axis Labels,我使用ggplot2在同一张图上绘制两个不同的离散变量,我得到的两个变量的断点明显不同。我想用所述标签的叠加值来标记x轴上的断裂,而不是相邻的断裂,我成功地做到了这一点,但并没有真正在一个小图形上工作标签重叠 这是我正在使用的代码: plot<-ggplot(data, aes(xcut,modx, group=1))+ geom_smooth(aes(color="red"), se=F, linetype="dotted", size=1.25)+ geom_line(da

我使用ggplot2在同一张图上绘制两个不同的离散变量,我得到的两个变量的断点明显不同。我想用所述标签的叠加值来标记x轴上的断裂,而不是相邻的断裂,我成功地做到了这一点,但并没有真正在一个小图形上工作标签重叠

这是我正在使用的代码:

plot<-ggplot(data, aes(xcut,modx, group=1))+ 
  geom_smooth(aes(color="red"), se=F, linetype="dotted", size=1.25)+ 
  geom_line(data=data,aes(xcut,lowerx, color="red4"), size=1.5)+
  geom_line(data=data,aes(xcut,upperx, color="red4"), size=1.5)+
  geom_ribbon(data=data, aes(xcut,ymin=lowerx,ymax=upperx), fill="lightpink", alpha=0.4)+

  geom_smooth(data=databis, aes(xcut,modx, group=1, color="green"), se=F, linetype="dotted", size=1.25)+ 
  geom_line(data=databis,aes(xcut,upperx, color="green4"), size=1.5)+
  geom_line(data=databis,aes(xcut,lowerx, color="green4"), size=1.5)+
  geom_ribbon(data=databis, aes(xcut,ymin=lowerx,ymax=upperx), fill="chartreuse1", alpha=0.4)+

  ylim(min(data$lowerx,databis$lowerx),max(data$upperx,databis$upperx))+

  scale_colour_manual(name = 'Legend', 
                      values =c('red'='red','green'='green', 'green4'='green4', 'red4'='red4'), labels = c('','','',''))+
  scale_size_area() + 
  xlab("") +
  ylab("")+
  labs(title='')

plot<-plot + scale_x_discrete(breaks=c(1:10), labels=c(label6Ex$label))
很抱歉,由于需要大量数据,我无法提供一个有效示例。基本上我使用了x变量,一个相关的modx变量和一个离散变量xcut,它就是x切十个断点。我有两个不同的dataframes data和databis,其中所有变量的定义都是相似的,但显然,这两个dfs的标签是不同的。我最后添加的标签已经分别确定;正如我所说,我尝试为每个中断添加两个标签:

plot<-plot + scale_x_discrete(breaks=c(1:10), labels=c(paste(labeldatax$label,labeldatabisx$label,sep=" - ")))
这给了我这个

但对我来说,将两个标签垂直叠加会更方便。欢迎在这件事上提供任何帮助


提前感谢。

只需将sep=-替换为sep=\n即可

我真不敢相信事情会这么简单。。。非常感谢,它工作得非常好!棒 极 了我把它作为一个答案转发给你,这样你就可以结束这个问题,如果这是最好的解决方案。