如何在ggplot2图的末尾删除间隙

use*_*311 6 r ggplot2

我的输入文件在PasteBin上.

我目前的图表代码是:

 #Input and data formatting
 merg_agg_creek<-read.table("merged aggregated creek.txt",header=TRUE)
 library(ggplot2)
 library(grid)
 source("http://egret.psychol.cam.ac.uk/statistics/R/extensions/rnc_ggplot2_border_themes.r")

 CombinedCreek<-data.frame(merg_agg_creek)
 Combined<-CombinedCreek[order(CombinedCreek[,2]),]
 Combined$Creek <- factor(rep(c('Culvert Creek','North Silcox','South Silcox','Yucca Pen'),c(32,57,51,31)))  
 Combined$Creek<-factor(Combined$Creek,levels(Combined$Creek)[c(1,4,3,2)])

 #The Graph Code

 creek <-ggplot(Combined,aes(Month,Density,color=factor(Year),shape=factor(Year)))+scale_color_discrete("Year")+scale_shape_discrete("Year")
 creek<-creek + facet_grid(Creek~. ,scales = "free_y")
 creek <- creek + geom_jitter(position = position_jitter(width = .3))
 creek<-creek+scale_color_grey("Year",end=.6)+theme_bw()
 creek<-creek+scale_y_continuous(expression("Number of prey captured " (m^2) ^-1))
 creek<-creek+opts( panel.border = theme_L_border() )+ opts(axis.line = theme_segment())
 creek<-creek+opts(panel.grid.minor = theme_blank())+opts(panel.grid.major = theme_blank())
 creek<-creek+scale_x_discrete("Month",breaks=c(2,5,8,11),labels=c("February","May","August","November"))
 creek
Run Code Online (Sandbox Code Playgroud)

结果图是:
图形

我的问题是,通过在"scale_x_discrete"中创建中断和标签,在图的右侧,12月的数据和构面标签之间存在较大的间隙.我尝试通过在"scale_x_discrete:"命令中添加"limits = c(0,13)"来消除这种差距,但结果图会破坏x标签.

如何消除这种差距?我的剧情创作中是否存在根本缺陷?

谢谢!

编辑:Didzis回答了下面的问题.我只需要从scale_x_discrete更改为scale_x_continuous

Did*_*rts 4

由于数据中的月份是数字,请尝试替换

 scale_x_discrete("Month",breaks=c(2,5,8,11),labels=c("February","May","August","November")) 
Run Code Online (Sandbox Code Playgroud)

 scale_x_continuous("Month",breaks=c(2,5,8,11),labels=c("February","May","August","November"))
Run Code Online (Sandbox Code Playgroud)

保持所有其他参数相同