我的输入文件在 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
结果图是:
Graph
我的问题是,通过在“scale_x_discrete”中创建中断和标签,在图的右侧,12 月的数据和构面标签之间存在很大的差距。我尝试通过在“scale_x_discrete: 命令”中添加“limits=c(0,13)”来消除这个差距,但生成的图形会破坏 x-labels。
我如何消除这个差距?我的情节创作是否存在根本性缺陷?
谢谢!
编辑:Didzis 回答了下面的问题。我只需要从 scale_x_discrete 更改为 scale_x_continuous