2012-07-17 25 views
5

我做了2個稱爲beta和km的泡泡圖。我想並排比較這些情節,但scale_area似乎有所不同,這使得難以根據氣泡的大小在視覺上比較2個情節。ggplot2:如何手動調整scale_area

如果您注意到以下圖表中的圖例,則尺度不同。我認爲這是因爲betaGSD5數據集中最高的BiasAM值爲64,kmGSD5數據爲100。

如何手動更改scale_area以使betaPlot比例匹配kmPlot比例?

也有可能手動設置圖例中斷嗎?不是自動生成,而是可以指定我的傳說,但是我想要這樣嗎? 0-10, 10-30,30-50 , 50-70, 70-100,

betaGSD5數據:https://dl.dropbox.com/u/63947093/betaGSD5.csv

kmGSD5數據: https://dl.dropbox.com/u/63947093/kmGSD5.csv

這裏是測繪區代碼

betaPlot <- ggplot(betaGSD5, aes(N,PctCens,size=BiasAM,label=NULL)) + 
    geom_point(colour="red", shape=16) +scale_area(to=c(1,10)) + 
    xlab("Sample size") + ylab("Percent censored") + 
    xlim(0,100)+ ylim(0,100) + 
    theme_bw()+ 
    opts(
#legend.position='none', 
    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), #size=15 #hjust:move  horizonal, vjust-move verticall 
    axis.title.y=theme_text(face='bold',angle=90, vjust=0.2,size =12)) 
print(betaPlot) 

enter image description here

KM情節

kmPlot <- ggplot(kmGSD5, aes(N,PctCens,size=NewBiasAMpct,label=NULL)) + 
    geom_point(colour="red", shape=16) +scale_area(to=c(1,10)) + 
    xlab("Sample size") + ylab("Percent censored") + 
    xlim(0,100)+ ylim(0,100) + 
    theme_bw()+ 
    opts(
     #legend.position='none', 
    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), #size=15 #hjust:move  horizonal, vjust-move verticall 
    axis.title.y=theme_text(face='bold',angle=90, vjust=0.2,size =12)) 

print(kmPlot) 

enter image description here

+0

看一看'scale_area'和'continuous_scale' – mnel 2012-07-17 07:00:52

+0

@mnel:?我做到了。不是很有幫助。 – Amateur 2012-07-17 07:04:11

+0

@業餘,什麼沒有幫助?你不明白什麼? – 2012-07-17 08:54:16

回答

9

如果你希望他們並排側則它很容易。只是結合了數據集,並使用facet_wrap()

ggplot(dataset, aes(x = N, y = PctCens, size = BiasAM, label = NULL)) + 
    geom_point(colour="red", shape = 16) + 
    scale_size_area(limits = 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) + 
    theme_bw() + 
    theme(
    panel.grid.minor = element_blank(), 
    panel.background = element_blank(), 
    axis.ticks = element_blank(), 
    axis.title.x = element_text(face = 'bold', vjust = 0.2, size = 12), 
    axis.title.y = element_text(face = 'bold', angle = 90, vjust = 0.2, size = 12) 
) 

enter image description here

+0

非常感謝。 – Amateur 2012-07-17 14:20:50

+0

這是一個很棒的,正是我所需要的。但我遇到了ggplot折舊錯誤(特別是傳奇中斷)的一些問題。這個代碼是否有新的ggplot的更新版本? – Vinterwoo 2013-12-05 23:41:16

+1

代碼更新並在ggplot2 0.9.3.1 – Thierry 2013-12-12 13:10:05