2017-11-28 19 views
1

ggplotのstat_summary_binを指定されたx軸値でサマリーを作成するにはどうすればよいですか?たとえば、下のプロットでは、x = -1,0,1,2などのサマリーが必要です。今は-1.5、-0.5、0.5、1.5です。x軸目盛りでstat_summary_bin

df = data.frame(x=rnorm(1000), y=rnorm(1000)) 
ggplot(df, aes(x=x, y=y)) + 
stat_summary_bin(binwidth=1) 

enter image description here

+0

はたぶん 'breaks'を定義しますか? 'breaks = seq(-4.5、4.5、1)'のようなものです。 – aosmith

+0

@aosmithどこ? 'stat_summary_bin'は引数' break'を持たず、 'scale_x_continuous(breaks = -10:10)'を気にしません –

+0

ggplot2のバージョンで 'stat_summary_bin'に' breaks'引数がありますggplot2_2.2.1.9000)。それはドキュメントに説明されています。 – aosmith

答えて

2

これだけlate Julyに固定されたggplot2の既知のバグです。 breaks引数は次のバージョンで利用できるようになります

ggplot(df, aes(x = cut_width(x, 1, center = 0), y = y)) + 
    stat_summary_bin(binwidth = 1) + 
    scale_x_discrete(labels = -3:3, name = 'x') 

enter image description here

df <- data.frame(x = rnorm(1000), y = rnorm(1000)) 
ggplot(df, aes(x = cut_width(x, 1, center = 0), y = y)) + 
    stat_summary_bin(binwidth = 1) 

enter image description here

そして、x軸を修正する:バグレポートからの回避策、次の数週間以内にリリースされるはずのggplot2の経由

あなたが今ggplot2の開発バージョンを実行したい場合は、あなたがそうすることができる必要があります:

devtools::install_github("tidyverse/ggplot2") 
関連する問題