3

I have a set of data that is heavily right skewed. This creates a problem when doing a stat_bin2d plot. The result is most of the graph is dark blue with only a few points are a different color. I'd like to have the graph use the entire color range a bit more.

An example of the problem is from the ggplot documentation direction.

ggplot(diamonds, aes(carat, price)) + stat_bin2d()

The resulting graph has only a few positions that are something other than dark blue.

How can I adjust the mapping of the color range to show more detail? I know I can set the limits, but this doesn't exactly fit the bill as it makes anything outside the limits be gray.

ggplot(diamonds, aes(carat, price)) + stat_bin2d() + scale_fill_gradient(limits=c(1, 100))

Something like this with they gray appropriately colored too.

4

1 に答える 1

6

簡単な答えは

ggplot(diamonds, aes(carat, price)) + stat_bin2d() +
  scale_fill_gradient(trans="log10")

編集: より長い答えは、おそらく色または塗りつぶしスケールの何らかの変換が必要だということです。組み込みの変換については、の「関連項目」セクションを参照してください。

library(scales)
?trans

組み込みの変換が適切でない場合は、独自の変換を作成できます。これを行う方法を示す例については、カラー スケールの変換に関するこの SO の質問への回答を参照してください。

于 2013-03-14T18:54:05.937 に答える