3
set.seed(123)

library(data.table)
library(ggplot2)

dat=data.table(data.frame(a=rnorm(12),b=rnorm(12),c=rep(c(1,2),6),d=rep(c(1,2,3,4),3)))

ggplot(dat,aes(a,c,colour=d)) + geom_point() # line 1

ggplot(dat,aes(a,c,shape=d)) + geom_point() # line 2

1 行目は機能するのに 2 行目は機能しないのはなぜですか? プロットの見え方の違いだけではありませんか?

ありがとうございました

4

1 に答える 1

6

エラー メッセージは、何が問題なのかを示しています。

Error: A continuous variable can not be mapped to shape

shape係数が必要です:

ggplot(dat,aes(a,c,shape=factor(d))) + geom_point() 

またggplot(dat,aes(a,c,colour=factor(d))) + geom_point()、連続カラー スケールと比較して (離散カラー スケール) がどのように見えるかを確認します。

于 2013-04-30T12:31:32.050 に答える