9
以下のggplotで線種を調整したいと思います。私はdata.frame dfの中に別の列を導入して線種を表現しますが、それを因子に変換すると、 "method"の代わりに線種が凡例に現れます(試行3参照)。ggplot2:行の種類を調整する方法+凡例の順序は?
凡例で「方法」を取得するにはどうすればよいですか?最後に、私は自由に自由にこれらの線種は、凡例に表示される順序を選択し、
- できるようにしたいと思いテキスト。ここで
私の試みは、以下のとおりです。linetype
として
require(ggplot2)
set.seed(1)
df <- data.frame(x=c(1:4, 2:5),
method=rep(c("a", "b"), each=4),
lt=rep(c(5,3), each=4),
value=rep(c(0,1), each=4)+runif(8))
## trial 1:
ggplot(df, aes(x=x, y=value)) +
geom_point() +
geom_line(aes(group=method, linetype=method))
# fine, but not the linetypes I would like to have
## trial 2:
ggplot(df, aes(x=x, y=value)) +
geom_point() +
geom_line(aes(group=method, linetype=lt))
# correct linetypes, but no legend
## trial 3:
ggplot(df, aes(x=x, y=value)) +
geom_point() +
geom_line(aes(group=method, linetype=as.factor(lt)))
# legend, but not the correct one (I would like to have the "group"ing
# variable "method" in the legend as in trial 1)
'+ scale_linetype(名= "法")'私の伝説のタイトル "メソッド" を与える裁判3 – Chase
で動作するようですが、それでも私は "3" と「5を取得します試行1のように "a"と "b"の代わりに伝説のテキストとして –