私は、折れ線グラフと破線グラフの2つの線グラフをプロットしようとしています。プロット領域では成功しましたが、伝説には問題があります。ggplot2 change line type
私はChanging the line type in the ggplot legendのような投稿を見ましたが、解決できないようです。どこが間違っていたのですか?
library(ggplot2)
year <- 2005:2015
variablea <- 1000:1010
variableb <- 1010:1020
df = data.frame(year, variablea, variableb)
p <- ggplot(df, aes(x = df$year)) +
geom_line(aes(y = df$variablea, colour="variablea", linetype="longdash")) +
geom_line(aes(y = df$variableb, colour="variableb")) +
xlab("Year") +
ylab("Value") +
scale_colour_manual("", breaks=c("variablea", "variableb")
, values=c("variablea"="red", "variableb"="blue")) +
scale_linetype_manual("", breaks=c("variablea", "variableb")
, values=c("longdash", "solid"))
p
両方のラインは、凡例に固体として見えることに注意してください。
データを 'tidyr :: gather'で再整理してデータを1つの列に入れると、それはうまくいくでしょう –