I want to print a bubble chart in R. The problem I run into is that both, my x and my y axis are discrete. In theory this means a lot of data points (bubbles) end up on the same coordinate. I would rather have them scattered around the data point, but still within a quadrant that makes clear the bubble belongs to the respective x/y coordinate.
I think it is best demonstrated by a little example. The following code should highlight the problem:
# Example
require(ggplot2)
zz <- textConnection("Row PowerSource ProductSegment Price Model ManufacturingLocation Quantity
1 High SegmentA Low ModA LocationA 5000
2 Low SegmentB Low ModB LocationB 25000
3 High SegmentC Low ModC LocationC 15000
4 Low SegmentD High ModD LocationD 30000
5 High SegmentE High ModE LocationA 2500
6 Low SegmentA Low ModF LocationB 110000
7 High SegmentB Low ModG LocationC 20000
8 Low SegmentC Low ModH LocationD 3500
9 High SegmentD Low ModI LocationA 65500
10 Low SegmentE Low ModJ LocationB 145000
11 High SegmentA Low ModK LocationC 15000
12 Low SegmentB Low ModL LocationD 5000
13 High SegmentC Low ModM LocationA 26000
14 Low SegmentD Low ModN LocationB 14000
15 High SegmentE Mid ModO LocationC 75000
16 Low SegmentA High ModP LocationD 33000
17 High SegmentB Low ModQ LocationA 14000
18 Low SegmentC Mid ModR LocationB 33000
19 High SegmentD High ModS LocationC 95000
20 Low SegmentE Low ModT LocationD 4000
")
df2 <- read.table(zz, header= TRUE)
close(zz)
df2
ggplot(df2, aes(x = ManufacturingLocation, y = PowerSource, label = Model)) +
geom_point(aes(size = Quantity, colour = Price)) +
geom_text(hjust = 1, size = 2) +
scale_size(range = c(1,15)) +
theme_bw()
How can I scatter the bubbles a little bit to show the different products in each categories and their quantity?
(Apologies, I can't add an image at the moment because of too few reputations)