如何修复ggplot2中的轴断点?

时间:2014-08-12 16:25:02

标签: r ggplot2

数据

我有以下情节:

enter image description here

它是使用以下代码创建的:

ggplot(data=new.data, mapping=aes(x= m.speed*1.09728, y=m.gaptime)) + 
  geom_point(aes(shape=interaction(Vehicle.class,PrecVehClass)), size=3, fill="black") + 
  scale_shape_manual(values=c(1,25,12), name="Vehicle Following Case", 
                     labels = c("Car Following Car", "Truck Following Car", "Car Following Truck")) + 
  stat_smooth(aes(x= m.speed*1.09728, y=m.gaptime, linetype=interaction(Vehicle.class,PrecVehClass)),size=1,color="black",method="loess", alpha=0)  + 
  scale_linetype_manual(values=c("dotted", "solid", "longdash"), name="Vehicle Following Case",
                        labels = c("Car Following Car", "Truck Following Car", "Car Following Truck")) +
  scale_x_discrete(breaks=seq(5,90, by=5)) +
  labs(x='Mean Speed (Km/hr)', y='Mean Time Gap (s)') + 
  theme_bw() + my.theme()

问题

您可以看到x轴(75)上的最后一个刻度标记位于绘图的边界,左边的第一个框不包含任何数据。我在limits中尝试了不同的breaksscale_discrete,如代码所示,但无法解决此问题。请帮忙。

0 个答案:

没有答案