Position = "dodge" or "jitter" not working with geom_segments

Sorry for repost but I have a better working example of data that reflects my problem. I figured out how to supply custom colors that remain consistent even in the event of missing data (e.g. if Species in the below example omitted setosa, the colors should stay consistent). But now I'm unable to get the geom_segments to follow the "dodge" parameter. I've also tried "jitter" and even custom jittering using position_jitter(width=0.25).

colours <- c("#FF0000", "#33CC33", "#CCCCCC", "#FFA500", "#000000" )
iris$Month <- rep(seq(from=as.Date("2011-01-01"), to=as.Date("2011-10-01"), by="month"), 15)
d<-aggregate(iris$Sepal.Length, by=list(iris$Month, iris$Species), sum)
d$quota<-seq(from=2000, to=60000, by=2000)
colnames(d) <- c("Month", "Species", "Sepal.Width", "Quota")
d$Sepal.Width<-d$Sepal.Width * 1000
g1 <- ggplot(data=d, aes(x=Month, y=Quota, color="Quota")) + geom_line(size=1)
g1 + geom_segment(data=d, mapping=aes(x=Month, y=0, ymax=Sepal.Width, yend=Sepal.Width, xend=Month, group=Species, color=Species, size=1), position="dodge") + scale_color_manual(values=colours)

The geom_segments are overlapping and I'd like them to be next to each other. Previously I just created each segment one by one with their own layers and offset the x-axis (Month + 5, Month + 10, etc.). But I wasn't able to get the custom colors for each line that way.

Thanks for any guidance.

Answers


It sounds like you're trying to make a bar plot out of line segments... instead use:

ggplot(d, aes(x=Month, y=Sepal.Width)) + 
  geom_bar(stat='identity', position='dodge')

Need Your Help

Using __weak to modify storage of a parameter in implementation

objective-c memory-management automatic-ref-counting objective-c-blocks

Is it valid to use the __weak storage modifier in a method's implementation's signature? Especially if it is not part of the method's public signature? For example:

A good Java Tool to monitor the heap

java memory jvm windows-server-2008

I have been searching, and see that there is Jstat, VisualJVM, and even Eclipse mat tools, but they all seem to have the JDK needing to be installed.