6

私の入力ファイルは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

結果のグラフは次のとおりです
グラフ

私の問題は、「scale_x_discrete」でブレークとラベルを作成することにより、プロットの右側、12 月のデータとファセット ラベルの間に大きなギャップが存在することです。"limits=c(0,13)" を "scale_x_discrete: コマンドに追加してこのギャップを解消しようとしましたが、結果のグラフでは x ラベルが破棄されます。

その隙間をなくすにはどうすればいいですか?私のプロット作成に根本的な欠陥はありますか?

ありがとう!

編集:Didzisは以下の質問に答えました。scale_x_discrete から scale_x_continuous に変更するだけです

4

2 に答える 2

4

データの月は数値であるため、置き換えてみてください

 scale_x_discrete("Month",breaks=c(2,5,8,11),labels=c("February","May","August","November")) 

 scale_x_continuous("Month",breaks=c(2,5,8,11),labels=c("February","May","August","November"))

他のすべてのパラメータを同じままにする

于 2012-12-05T05:52:13.730 に答える
0

スケールで展開引数を使用する必要があります。余分なスペースはジッターが原因である可能性があると思いますが、-2 を指定すると端まで行きます。パディングが多すぎるのはほとんどバグのようです。

ggplot(Combined,aes(Month,Density,color=factor(Year),shape=factor(Year))) +
scale_shape_discrete("Year") +
facet_grid(Creek~. ,scales = "free_y") +
geom_jitter(position = position_jitter(width = .3)) +
scale_color_grey("Year",end=.6) +
theme_bw() +
scale_y_continuous(expression("Number of prey captured " (m^2) ^-1))+
scale_x_discrete("Month",breaks=c(2,5,8,11),labels=c("February","May","August","November"), expand= c(0,-2)) +
theme(
panel.grid.major=element_blank(),
panel.grid.minor=element_blank()
)
于 2012-12-04T21:03:45.000 に答える