Amateur
Amateur

Reputation: 1277

How to interpret bubble plot scale and plotting negative numbers with scale_area

I asked a question about making bubble charts in ggplot2 here.

My follow-up questions are:

1)how do I interprete the scale_size in the legend?

2) Does small dot (labeled 10) mean the data can be anything from 5-10? If the data for a particular point is 8, does scale_area function change the data point to 10 before it is presented as a dot size 10 on the graph.

3) is there a way to plot negative number on ggplot bubble chart? Some software can make the negative data a color bubble.

4) I tried to incorporate scale_area and scale_alpha but the legend shows 2 scales. I just want a combined one. How do I do that?

ggplot(dataset, aes(x = N, y = PctCens, size = BiasAM, alpha=BiasAM ,label = NULL)) +
geom_point(shape = 16) + 
scale_area(to = c(1, 10), breaks = c(0, 10, 30, 50, 70, 100)) +
scale_x_continuous("Sample size", limits = c(0, 100)) + 
scale_y_continuous("Percent censored", limits = c(0, 100)) +
facet_wrap(~Method,ncol=2) + 
theme_bw()+
opts(
panel.grid.minor = theme_blank(),
panel.background = theme_blank(),
axis.ticks = theme_blank(),
axis.title.x=theme_text(face='bold',vjust=0.2, size =12), 
axis.title.y=theme_text(face='bold',angle=90, vjust=0.2,size =12))

enter image description here

Upvotes: 3

Views: 1935

Answers (1)

Amateur
Amateur

Reputation: 1277

Here is how I ended up solving my problem with negative numbers in bubble chart.

The original BiasAM (called OrgBiasAM) variable has negative numbers so I took the absolute value of it and created a new variable called BiasAM which i used in the above code. To distinguish between the negative and positive numbers, I made a new categorical variable called BiasAMCat using ifelse statement

dataset$BiasAMCat <-ifelse(dataset$OrgBiasMA < 0, 'Negative', 'Positive')

The modified code is now:

ggplot(dataset, aes(x = N, y = PctCens, size = BiasAM, colour=factor(BiasAMCat) ,label =       NULL)) +
  geom_point(shape = 16) + 
  scale_area(to = c(1, 10), breaks = c(0, 10, 30, 50, 70, 100)) +
  scale_colour_manual(name=NULL, values=c('grey','black')) +  # for bw printing
  scale_x_continuous("Sample size", limits = c(0, 100)) + 
  scale_y_continuous("Percent censored", limits = c(0, 100)) +
  facet_wrap(~Method,ncol=2) + 
  theme_bw()+
  opts(
  panel.grid.minor = theme_blank(),
  panel.background = theme_blank(),
  axis.ticks = theme_blank(),
  axis.title.x=theme_text(face='bold',vjust=0.2, size =12), 
  axis.title.y=theme_text(face='bold',angle=90, vjust=0.2,size =12))

Note: If you like gradient color, you can use color_gradient as suggested by Andy W instead of scale_colour_manual.

Upvotes: 2

Related Questions