Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use geom_point {ggplot2} to get points on the ends of the bars without getting circles in the legend?

Tags:

r

ggplot2

I am trying to make a bar plot that has extra data on it. Associated with each data point is a value from a factor that indicates why the height is what it is. So far I'm reasonably happy with my results:

library(ggplot2)

tab <- read.table("http://www.cs.colorado.edu/~coxaj/table2.csv",
            header=T, sep=",", strip.white=T)
tab <- with(tab, tab[order(Analysis, -as.numeric(Analysis)), ])

bar_width <- 0.5
space_width <- 0.8

p <- ggplot(tab, aes(x=Filter,y=Depth,fill=Analysis)) +
  geom_bar(position=position_dodge(width=space_width), width=bar_width) +
  geom_point(position=position_dodge(width=space_width), aes(shape=Termination)) +
  scale_shape_manual(values=c(1,4,5,6)) +
  geom_hline(aes(yintercept=16, linetype=2)) +
  scale_x_discrete(name='') +
  scale_y_continuous(name='Search Depth') +
  scale_fill_manual(values=c("#E66101", "#FDB863", "#B2ABD2", "#5E3C99")) +
  theme_bw()

ggsave(filename='table2.pdf', height=3, width=8)

This produces a plot that looks like this: example output

The problem is that it puts these pointless circles in the legend for Analysis. I would like to remove that circle, but keep the legend. Does ggplot2 let me do this?

like image 319
Arlen Cox Avatar asked Jan 04 '12 16:01

Arlen Cox


1 Answers

try this:

p <- ggplot(tab, aes(x=Filter,y=Depth)) +
  geom_bar(aes(fill = Analysis), 
           position=position_dodge(width=space_width), width=bar_width) +
  geom_point(position=position_dodge(width=space_width), 
             mapping = aes(group = Analysis, shape=Termination)) +
...

enter image description here

like image 158
kohske Avatar answered Nov 16 '22 02:11

kohske