mydata <- structure(list(date = structure(c(17197, 17225, 17256, 17286,
17317, 17347, 17378, 17409, 17439, 17470, 17500, 17531), class = "Date"),
trend = c(50.0269807745231, 49.9079174041303, 49.7305604160741,
49.741183658644, 49.9452022771566, 50.170406217103, 50.3095823068472,
50.4182117454559, 50.5129008767132, 50.6000443177828, 50.732042763593,
50.8590001515567), seas = c(52.8086929944926, 50.1397887295428,
48.0247110747216, 48.3018488153966, 49.7687103342102, 51.4708124260815,
50.0353905837334, 56.7204402229887, 51.1256271469797, 49.5529917864331,
51.091476794446, 51.2993119413525), tot = c(54.512, 51.359,
46.913, 44.345, 46.287, 53.234, 54.535, 55.002, 50.817, 47.101,
52.462, 54.045)), .Names = c("date", "trend", "seas", "tot"
), row.names = c(NA, 12L), class = "data.frame")
Then I executed the the following steps:
library(ggplot2)
library(reshape2)
dt <- melt(mydata,id.vars='date')
dt$variable <- factor(dt$variable,
levels=c('trend','seas','tot'),
labels=c('Trend','Seasonality','Gross'))
p <- ggplot(dt, aes(x=date,y=value,color=variable)) +
scale_y_continuous(breaks=seq(40,60,by=2)) +
xlab(NULL) + ylab("MW") +
theme(legend.position="bottom", legend.title = element_blank()) +
geom_point(data = subset(dt, variable %in% "Gross"), aes(group = variable), shape=3) +
geom_line(data = subset(dt, variable != "Gross"), aes(group = variable)) +
scale_colour_manual("",breaks=c('Gross','Seasonality','Trend'), values=c("Gross"="black","Seasonality"="blue", "Trend"="red"))
I obtained the enclosed plot.
In the legend the colours of the symbols are correct but not the symbols.
In the legend I would like to have a black '+' for 'Gross', a dotted blue line for 'Seasonality' and a solid red line for 'Trend' ,horizontally lined up.