2016-10-07 12 views
1

を離散化した後ggplotカラースケールのラベルの順序は、次のサンプルデータセット考えてみましょう:もちろんResponse反転連続変数

mydata="theta,rho,Response 
0,0.8400000,0.0000000 
40,0.8400000,0.4938922 
80,0.8400000,0.7581434 
120,0.8400000,0.6675656 
160,0.8400000,0.2616592 
200,0.8400000,-0.2616592 
240,0.8400000,-0.6675656 
280,0.8400000,-0.7581434 
320,0.8400000,-0.4938922 
0,0.8577778,0.0000000 
40,0.8577778,0.5152213 
80,0.8577778,0.7908852 
120,0.8577778,0.6963957 
160,0.8577778,0.2729566 
200,0.8577778,-0.2729566 
240,0.8577778,-0.6963957 
280,0.8577778,-0.7908852 
320,0.8577778,-0.5152213 
0,0.8755556,0.0000000 
40,0.8755556,0.5367990 
80,0.8755556,0.8240077 
120,0.8755556,0.7255612 
160,0.8755556,0.2843886 
200,0.8755556,-0.2843886 
240,0.8755556,-0.7255612 
280,0.8755556,-0.8240077 
320,0.8755556,-0.5367990 
0,0.8933333,0.0000000 
40,0.8933333,0.5588192 
80,0.8933333,0.8578097 
120,0.8933333,0.7553246 
160,0.8933333,0.2960542 
200,0.8933333,-0.2960542 
240,0.8933333,-0.7553246 
280,0.8933333,-0.8578097 
320,0.8933333,-0.5588192 
0,0.9111111,0.0000000 
40,0.9111111,0.5812822 
80,0.9111111,0.8922910 
120,0.9111111,0.7856862 
160,0.9111111,0.3079544 
200,0.9111111,-0.3079544 
240,0.9111111,-0.7856862 
280,0.9111111,-0.8922910 
320,0.9111111,-0.5812822 
0,0.9288889,0.0000000 
40,0.9288889,0.6041876 
80,0.9288889,0.9274519 
120,0.9288889,0.8166465 
160,0.9288889,0.3200901 
200,0.9288889,-0.3200901 
240,0.9288889,-0.8166465 
280,0.9288889,-0.9274519 
320,0.9288889,-0.6041876 
0,0.9466667,0.0000000 
40,0.9466667,0.6275358 
80,0.9466667,0.9632921 
120,0.9466667,0.8482046 
160,0.9466667,0.3324593 
200,0.9466667,-0.3324593 
240,0.9466667,-0.8482046 
280,0.9466667,-0.9632921 
320,0.9466667,-0.6275358 
0,0.9644444,0.0000000 
40,0.9644444,0.6512897 
80,0.9644444,0.9997554 
120,0.9644444,0.8803115 
160,0.9644444,0.3450427 
200,0.9644444,-0.3450427 
240,0.9644444,-0.8803115 
280,0.9644444,-0.9997554 
320,0.9644444,-0.6512897 
0,0.9822222,0.0000000 
40,0.9822222,0.6751215 
80,0.9822222,1.0363380 
120,0.9822222,0.9125230 
160,0.9822222,0.3576658 
200,0.9822222,-0.3576658 
240,0.9822222,-0.9125230 
280,0.9822222,-1.0363380 
320,0.9822222,-0.6751215 
0,1.0000000,0.0000000 
40,1.0000000,0.6989533 
80,1.0000000,1.0729200 
120,1.0000000,0.9447346 
160,1.0000000,0.3702890 
200,1.0000000,-0.3702890 
240,1.0000000,-0.9447346 
280,1.0000000,-1.0729200 
320,1.0000000,-0.6989533" 

foobar <- read.csv(text = mydata) 

は連続変数であり、それは連続カラースケールでプロットされなければなりません。しかし、離散カラースケールを使用するように求められているので、私はvalueを離散化する必要があります。私の自然なアプローチは、この質問への第二の答えと同じで、次のようになります。

easiest way to discretize continuous scales for ggplot2 color scales?

library(ggplot2) 
ggplot(data = foobar, aes(x = theta, y = rho, fill = cut(Response, breaks = 5))) + 
geom_tile() + 
coord_polar(theta = "x", start = -pi/9) + 
scale_x_continuous(breaks = seq(0, 360, by = 45)) + 
scale_y_continuous(limits = c(0, 1)) + 
scale_fill_brewer(palette = "RdYlGn", direction = -1, name = "Response") 

enter image description here

つまりしかし、私はラベルが減少にプロットされたいですすなわち、連続した変数であれば、同じ注文ggplot2が使用されます。私の例では、これは赤色に対応する(0.644, 1.08]というラベルが上にあり、青色に対応する(-1.08, 0.644]というラベルが凡例の下にあることを意味します。どうすれば入手できますか?

答えて

1

引数reverseは、引数を使用して凡例を逆にすることができます。

scale_fill_brewer(palette = "RdYlGn", direction = -1, name = "Response", 
         guide = guide_legend(reverse = TRUE)) 
+0

優秀、ありがとう! – DeltaIV