I have a line plot of prices for three stocks, which I normalise by taking the percentage change from the beginning of the period I am looking at. This seems to work fine, b
In ggplot
the legend matches the plot itself. So, to get circles or squares in the legend you need to add circles or squares to the plot.
This can be done with geom_point(shape=...)
. shape=1
generates circles, shape=7
generates squares.
chart1 + geom_point(shape=7)
You can define new geom like this:
GeomLine2 <- proto(GeomLine, {
objname <- "line2"
guide_geom <- function(.) "polygon"
default_aes <- function(.) aes(colour = "black", size=0.5, linetype=1, alpha = 1, fill = "grey20")
})
geom_line2 <- GeomLine2$build_accessor()
chart1 <- ggplot(data=changes,aes(x=Date, y=value, colour=variable, fill = variable))
chart1 <- chart1 + geom_line2(lwd=0.5) + ylab("Change in price (%)") + xlab("Date") +
labs(colour="Company", fill = "Company")
print(chart1)
Not sure but note that this will not work in the next version of ggplot2.