2016-08-08 8 views
1

私はこの1つのように見えるデータフレーム持っている:私は「ピラミッド」を作りたかったので、私はネガにNさんのいくつかを作るために必要なggplot2棒グラフの負のx軸の区切り(ラベル)を正の値に変更するにはどうすればよいですか?

df <- structure(list(gender = c("male", "male", "male", "female", "female", 
"female", "male", "male", "male", "male", "male", "female", "female", 
"female"), agegroup = c("-24", "25-34", "45-54", "-24", "25-34", 
"35-44", "-24", "25-34", "35-44", "65-", "unknown", "-24", "25-34", 
"35-44"), N = c(-2, -4, -1, 3, 4, 1, -3, -14, -1, -1, -2, 3, 
3, 1), N2 = c(2, 4, 1, 3, 4, 1, 3, 14, 1, 1, 2, 3, 3, 1), location = c("here", 
"here", "here", "here", "here", "here", "there", "there", "there", 
"there", "there", "there", "there", "there")), .Names = c("gender", 
"agegroup", "N", "N2", "location"), row.names = c(NA, 14L), class = "data.frame") 

を。このように:

ggplot(biofile2, aes(x = agegroup, y = N , fill = gender),color=gender) + 
geom_bar(stat="identity", size=.3, position="identity")+ 
facet_wrap(~ location,ncol=2)+ 
coord_flip() 

私は意図したようです。残されているのは、-10と-5をポジティブに戻すことだけです。プロットの外観を変えずにこれを行う方法はありますか?

+0

@Axemanのおかげ!どのラベルが事前にわかっていなければ、プログラムでラベルを変更する方法はありますか? – rdatasculptor

+1

@Axeman、これを回答として追加すると、私はそれを受け入れることになります。再度、感謝します! – rdatasculptor

答えて

0

単純にすべての軸ラベルを正の値にする、つまり絶対値をとるようにしたいようです。これは、scale_*_continuousbreakslabelsという引数で行うことができます。この場合、coord_flipの前に参照する必要があるので、y軸を変換する必要があることに注意してください。 pretty機能は、都合かなり軸の区切りを生成するために使用することができます。

これはあなたのプロットを追加します。

scale_y_continuous(breaks = pretty(df$N), labels = abs(pretty(df$N)) 
関連する問題