2012-11-25 10 views
10

両方のプロットでポイントは異なって見えますが、なぜですか?geom_pointでは実際にサイズはどういう意味ですか?

mya <- data.frame(a=1:100) 

ggplot() + 
    geom_path(data=mya, aes(x=a, y=a, colour=2, size=seq(0.1,10,0.1))) + 
    geom_point(data=mya, aes(x=a, y=a, colour=1, size=1)) + 
    theme_bw() + 
    theme(text=element_text(size=11)) 

ggplot() + 
    geom_path(data=mya, aes(x=a, y=a, colour=2, size=1)) + 
    geom_point(data=mya, aes(x=a, y=a, colour=1, size=1)) + 
    theme_bw() + 
    theme(text=element_text(size=11)) 

?aes_linetype_size_shape

...

# Size examples 
# Should be specified with a numerical value (in millimetres), 
# or from a variable source 
を説明します。しかし、私のコードでは違って見えます。

答えて

13

コードにはいくつか混乱が生じています。 aes関数を意図していない方法で使用しているようです。 sizeの問題と同様に、複数の伝説を得ています.ggplotは色について混乱していると思います。

aes関数は、美学をデータの変数にマップするために使用されますが、それを使用して美学を定数に設定しています。さらに、aes関数を使用して2つの異なる美学を設定しています。 sizeを定数に設定しても、ggplot2は2つの別々の(パスとポイント)サイズマッピングが嫌いです。さらに、同じことをカラーマッピングで行います。

sizeおよびcolourは、一定値に設定されているため、aes機能の外に移動します。また、最初のプロットのパスのsizeに関しては、おそらくsize変数をデータフレームに追加する方が安全です。 (私はポイントとパスの両方が見えるようにあなたのデータを少し修正しました)そして、期待通りに、最初のプロットの1つの凡例が描画されます。

library(ggplot2) 
mya <- data.frame(a=1:10, size = seq(10, 1, -1)) 

ggplot() + 
    geom_path(data=mya, aes(x=a, y=a, size=size), colour = 2) + 
    geom_point(data=mya, aes(x=a, y=a), colour = 1, size = 3) + 
    theme_bw() + 
    theme(text=element_text(size=11)) 

ggplot() + 
    geom_path(data=mya, aes(x=a, y=a), colour = 2, size = 1) + 
    geom_point(data=mya, aes(x=a, y=a), colour = 1, size = 3) + 
    theme_bw() + 
    theme(text=element_text(size=11)) 

enter image description here

関連する問題