3

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

4

1 回答 1

2

这是我最终解决气泡图中负数问题的方法。

原始 BiasAM(称为 OrgBiasAM)变量具有负数,因此我取它的绝对值并创建了一个名为 BiasAM 的新变量,我在上面的代码中使用了它。为了区分负数和正数,我使用 ifelse 语句创建了一个名为 BiasAMCat 的新分类变量

数据集$BiasAMCat <-ifelse(数据集$OrgBiasMA < 0, 'Negative', 'Positive')

修改后的代码现在是:

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

注意:如果您喜欢渐变色,可以按照 Andy W 的建议使用 color_gradient 而不是 scale_colour_manual。

于 2012-07-27T21:40:35.300 回答