Hi all,
I am trying to get a dashed line into the legend. I have searched
through many posts and Hadley's book but I can't work it out.
I have a stacked bar plot, along with two lines. It is in black and
white for publication so to differentiate between the lines, one is
solid and one is dashed. The dashed line shows in the plot but I am
unable to get it to show in the legend. I am including the pdf output
just to be thorough but can't work out had to include my csv and pdf
files.
Here is my code:
# The plot
samplePlot<- ggplot(sampleDataSet) +
geom_bar(aes(dayCount, upper, fill = "Upper"), stat = "identity") +
geom_bar(aes(dayCount, lower, fill = "Lower"), stat = "identity") +
scale_fill_manual("The Steps", c("Upper" = "grey", "Lower" = "light
grey")) +
geom_line(aes(dayCount, count, colour = "Count"), size = 0.3) +
geom_line(aes(dayCount, oldSample, colour = "Old Sample"), linetype =
2, size = 0.3) +
scale_colour_manual("Count and Old Sample", c("Count" = "black", "Old
Sample" = "black")) +
opts(title = "Count Plotted with Steps and Old Sample") +
labs(x = "Day Count", y = "Numbers", fill = "The Steps") +
theme_bw()
print(samplePlot)
# Output plot as a PDF
pdf("/Users/Carl/Desktop/ggpplot_group_sample.pdf", width = 10, height
= 8)
print(samplePlot)
dev.off()
I have ensured that I have the latest version of R and recently did
the ggplot2 update.
Any help appreciated.
Cheers,
Carl.
SDS.bar<-cbind(sampleDataSet[1], sampleDataSet[3], sampleDataSet[5])
SDS.bar <- melt(SDS.bar, id.vars="dayCount")
SDS.line<-cbind(sampleDataSet[1], sampleDataSet[2], sampleDataSet[6])
SDS.line <- melt(SDS.line, id.vars="dayCount")
samplePlot<- ggplot() +
geom_bar(data=SDS.bar, aes(x=dayCount, y=value, fill=variable),
stat = "identity") +
#scale_fill_grey("The Steps", labels = c("Upper", "Lower"), breaks
= c("Upper", "Lower"), c("Upper" = "grey", "Lower" = "light grey")) +
geom_line(data=SDS.line, aes(dayCount, value, linetype =
variable), size = 0.3) +
#scale_linetype_manual("Count and Old Sample", c(1,2), labels =
c("Count" = "solid", "Old Sample" = "dashed")) +
opts(title = "Count Plotted with Steps and Old Sample",
legend.key.size = unit(2, "lines")) +
labs(x = "Day Count", y = "Numbers", fill = "The Steps") +
theme_bw()
print(samplePlot)
Every time I try and use the manual scales it breaks it though.
Perhaps someone else can fill in the holes or knows a way without
manipulating the data.
Brandon
> --
> You received this message because you are subscribed to the ggplot2 mailing list.
> Please provide a reproducible example: http://gist.github.com/270442
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
SDS.bar<-cbind(sampleDataSet[1], sampleDataSet[3], sampleDataSet[5])
SDS.bar <- melt(SDS.bar, id.vars="dayCount")
SDS.line<-cbind(sampleDataSet[1], sampleDataSet[2], sampleDataSet[6])
SDS.line <- melt(SDS.line, id.vars="dayCount")
samplePlot<- ggplot() +
geom_bar(data=SDS.bar, aes(x=dayCount, y=value, fill=variable),
stat = "identity") +
scale_fill_grey(name= "The Steps", breaks= c("upper","lower"),
start= 0.8, end=0.65) +
geom_line(data=SDS.line, aes(dayCount, value, linetype =
variable), size = 0.3) +
opts(title = "Count Plotted with Steps and Old Sample",
legend.key.size = unit(2, "lines")) +
labs(x = "Day Count", y = "Numbers", fill = "The Steps") +
theme_bw()
print(samplePlot)
I really need to work on my knowledge of scales. :/
Brandon