ggplot2:如何手动调整scale_area [英] ggplot2: how to manually adjust scale_area
问题描述
如果您注意到以下图表中的图例,则尺度不同。我认为这是因为betaGSD5数据集中最高的BiasAM值为64,kmGSD5数据为100。如何手动更改scale_area以使betaPlot比例与kmPlot相匹配规模?
也可以手动设置图例符号?不是自动生成,而是可以指定我的传说,但是我想要这样吗?
0-10,
10-30,
30-50,
50-70,
70-100,
<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(color =red,shape = 16)+ scale_area(to = c(1,10))+
xlab(样本量)+ ylab(百分比审查)+
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 #h ):
print(betaPlot)$ b axis_title.y = theme_text(face ='bold',angle = 90,vjust = 0.2,size = 12) $ b
KM plot
kmPlot< / p> ; - ggplot(kmGSD5,aes(N,PctCens,size = NewBiasAMpct,label = NULL))+
geom_point(color =red,shape = 16)+ scale_area(to = c(1,10)) +
xlab(样本量)+ ylab(百分比审查)+
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)
如果你想要他们并排,那么这很容易。结合数据集和使用facet_wrap()
ggplot(数据集,aes(x = N,y = PctCens,size = BiasAM ,label = NULL))+
geom_point(color =red,shape = 16)+
scale_size_area(limits = c(1,10),breaks = c(0,10,30,50 ,70,100))+
scale_x_continuous(样本大小,限制= c(0,100))+
scale_y_continuous(Percent Censored,limits = c(0,100))+
facet_wrap(〜Method)+
theme_bw()+
主题(
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(
$ b $ p>
I have made 2 bubble plots called beta and km. I would like to compare the plots side-by-side but the scale_area seem to be different which makes it difficult to visually compare 2 plots based on the size of the bubbles.
If you notice the legends on the plots below, the scales are different. I think it is because highest BiasAM value on the betaGSD5 dataset ~ 64 and kmGSD5 data =100.
How can I manually change the scale_area such that the betaPlot scale match the kmPlot scale?
Also is it possible to manually set the legend breaks? Instead of being automatically generated, can specify I the legend however I want like this?
0-10,
10-30,
30-50,
50-70,
70-100,
100
betaGSD5 data: https://dl.dropbox.com/u/63947093/betaGSD5.csv
kmGSD5 data:
https://dl.dropbox.com/u/63947093/kmGSD5.csv
Here is beta plot code
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)
KM plot
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)
解决方案 If you want them side-by-side then it's very easy. Just combine both dataset and use 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)
)
这篇关于ggplot2:如何手动调整scale_area的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!