Bullet graph in ggplot2?

1,544 views
Skip to first unread message

since1968

unread,
May 11, 2010, 10:58:17 AM5/11/10
to ggplot2
I'd like to build a bullet chart (example here): http://www.perceptualedge.com/blog/?p=217

Here is my data:

head(scores)

MCRNUM Measure Score Avg Top90thPctl
1 10001 AMI-1 10 8.25 10
2 10001 AMI-2 10 7.90 10
3 10001 AMI-3 10 6.62 10
4 10001 AMI-4 10 6.65 10
5 10001 AMI-5 10 7.96 10

I want to map the following values:

Symbol marker for comparative measure: Top90thPctl
Performance measure bar: Score
Background fill: Avg

This is a start, but I don't really understand how to layer and format
the other values:

qplot(Top90thPctl, Measure, data = scores)

Has anyone done a bullet chart in R and ggplot2?

Thank you.

--
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

David Winter

unread,
May 11, 2010, 6:45:12 PM5/11/10
to since1968, ggplot2
Here's something to play with, two layers of geom_bar and one of geom_point.



fake.data <- data.frame(measure=letters[1:10],
value=rpois(10,5),
mean=rpois(10,5),
target=rpois(10,7) )

p <- ggplot(fake.data, aes(value, measure) )

p + geom_bar(fill="grey", width=0.5) +
geom_bar(aes(measure, value), width=0.2) +
geom_point(aes(measure, target), colour="red")

since1968

unread,
May 16, 2010, 7:34:12 PM5/16/10
to ggplot2
On May 11, 6:45 pm, David Winter <david.win...@gmail.com> wrote:
> Here's something to play with, two layers of geom_bar and one of geom_point.

Thanks David, that's a big help. Here it is, clean up:

fake.data <- data.frame(measure=letters[1:10], value=rpois(10,5),
mean=rpois(10,5), target=rpois(10,5) )
p <- ggplot(fake.data, aes(measure, value) )
p <- p + geom_bar(fill="grey", width=0.5)
p <- p + geom_bar(aes(measure, mean), width=0.2)
p <- p + geom_point(aes(measure, target), colour="red")
p <- p + coord_flip()
p

I'm still working on getting the point to look like a bar, but that is
pretty close.

Gerry

unread,
May 17, 2010, 8:47:46 PM5/17/10
to ggplot2
Try this one for your bar solution:

fake.data <- data.frame(measure=letters[1:10], value=rpois(10,5),
mean=rpois(10,5), target=rpois(10,5) )
p <- ggplot(fake.data, aes(measure, value) )
p <- p + geom_bar(fill="grey", width=0.5)
p <- p + geom_bar(aes(measure, mean), width=0.2)
p <- p + geom_point(aes(measure, target), colour="red")
p <- p + geom_errorbar(aes(y = target,x = measure, ymin = target,ymax
= target), width = .45)
p <- p + coord_flip()
p

cheers
Gerry

since1968

unread,
May 22, 2010, 5:55:34 PM5/22/10
to ggplot2
Perfect. Thank you.
Reply all
Reply to author
Forward
0 new messages