2

重複の可能性:
ggplot2 を使用して、軸にブレークを挿入できますか?

次の ggplot2 コードを使用して、faced_grid 棒グラフを生成しています。

ggplot(plotobj, aes(as.factor(gm) , peaks, fill=rvalue)) +
  geom_bar(stat="identity") +
  facet_grid(rvalue ~ .,scales="free") + 
  opts(legend.position = "none")

次のプロットが得られます (最初のファセットのスクリーンショット)。 ggplot2 バープロット軸の問題

ご覧のとおり、1 つの外れ値のために y 軸が非常に高い値に伸びています。私がやりたいのは、2e+05 までのティックを増やしてから、5e+05 に直接向かうティックを 1 つだけ持つことで、より賢明なスケーリングを作成することです。この方法では、スケーリングは線形ではなくなりますが、カテゴリの 1 つに大きなピークがあることを示すことができます。

ggplot2でこれを簡単に行う方法はありますか? これを行うためのRトリックはありますか? 可能であれば、 ylim のようなものを使用して、トップを表示しないようにしたくありません。

4

1 に答える 1

2

y 軸で変換を使用できます。再現可能な例を提供しなかったため、テストされていません。

ggplot(plotobj, aes(as.factor(gm) , peaks, fill=rvalue)) +
    geom_bar(stat="identity") + facet_grid(rvalue ~ .,scales="free") + 
    opts(legend.position = "none") + scale_y_log10()
ggplot(plotobj, aes(as.factor(gm) , peaks, fill=rvalue)) +
    geom_bar(stat="identity") + facet_grid(rvalue ~ .,scales="free") + 
    opts(legend.position = "none") + scale_y_sqrt()
ggplot(plotobj, aes(as.factor(gm) , peaks, fill=rvalue)) +
    geom_bar(stat="identity") + facet_grid(rvalue ~ .,scales="free") + 
    opts(legend.position = "none") + coord_trans(y = "log10")
ggplot(plotobj, aes(as.factor(gm) , peaks, fill=rvalue)) +
    geom_bar(stat="identity") + facet_grid(rvalue ~ .,scales="free") + 
    opts(legend.position = "none") + coord_trans(y = "sqrt")
于 2012-06-12T10:36:41.937 に答える