ggplot2でgeom_smoothを使用してプロットの凡例を変更することに苦労しているという非常に単純な問題があります。ここでggplot2でgeom_smoothを使用してプロットの凡例を変更する
は私のコードです: "グループ" から "伝説" にして "0" から:すなわち:
p1<- mtcars$group <- factor(mtcars$vs)
ggplot(mtcars, aes(x=mpg, y=disp, group=group)) +
geom_smooth(method=lm, se=FALSE,fullrange=TRUE, show.legend=TRUE,aes(linetype=group), colour="black")
p1
私がやりたい何か、ラベルを変更で「実験」に、「1」を「制御」に設定します。私は、ラボの引数をaddedingとscale_fill_discreteを使用してこれを実行しようとしました:
p2<- ggplot(mtcars, aes(x=mpg, y=disp, group=group)) +
geom_smooth(method=lm, se=FALSE,fullrange=TRUE, show.legend=TRUE,aes(linetype=group), colour="black")+
labs(linetype="Legend")+
scale_fill_discrete(labels=c("Experiment", "Control"))
p2
結果は伝説のタイトル、(p2)を変化させるが、それでもラベルを変更しません。何か案は?
EDIT:
これは、問題を解決し、迅速回答に感謝します:
ggplot(mtcars, aes(x=mpg, y=disp, group=group)) +
geom_smooth(method=lm, se=FALSE,fullrange=TRUE, show.legend=TRUE,aes(linetype=group), colour="black")+
labs(linetype="Legend")+
scale_linetype_discrete(labels=c("Experiment", "Control"))
私のミスがscale_fill_discrete
代わりのscale_linetype_discrete
を使用していました。
使用 'scale_linetype_discreteを()'の代わりに、返信用 – Nate
感謝を埋めるが、これはエラーを与える:_ERROR:非function_を適用しようとすると: **編集**:心配しないで、コードを再実行すると、結果はまさに私が探していたものです。ありがとう! –