geom_point指向手动缩放

时间:2015-03-31 08:07:16

标签: r plot scaling

我得到了一些数据(名为result.df),如下所示:

    orgaName                  abundance          pVal         score        
     A                        3          9.998622e-01     1.795338e-04
     B                        2          9.999790e-01     1.823428e-05
     C                        1          2.225074e-308    3.076527e+02
     D                        1          3.510957e-01     4.545745e-01

依旧......

我现在正在绘制的是:

p1 <- ggplot(result.df, aes(log2(abundance), (1-pVal), label=orgaName)) +
   ylab("1 - P-Value")+
   xlab("log2(abundance)")+
   geom_point(aes(size=score))+
   ggtitle(colnames(case.count.matrix)[i])+
   geom_text(data=subset(result.df, pVal < 0.05),hjust=.65, vjust=-1.2,size=2.5)+       
   geom_hline(aes(yintercept=.95), colour="blue", linetype="dashed")+
   theme_classic()

一切正常,看起来相当不错。但是,我想要的是缩放通过

引入的点大小
geom_point(aes(size=score))+

按比例缩放固定值。所以传说应该以十进制对数缩放,但分数应该保持不变。这样低分几乎消失,大分数与不同“result.df”之间的分数大小相当。

修改

在检查了@roman和@ vrajs5的评论之后,我能够制作出像这样new plot的情节。 使用以下代码:

   ggplot(result.df, aes(log2(abundance), (1-pVal), label=orgaName)) +
   ylab("1 - P-Value")+
   xlab("log2(abundance)")+
   geom_point(aes(size=score))+
   ggtitle(colnames(case.count.matrix)[i])+    
   #geom_text(data=subset(result.df, pVal < 0.05 & log2(abundance) > xInt),hjust=.65, vjust=-1.2,size=2.5)+
   geom_text(data=subset(result.df, pVal < 0.05),hjust=.65, vjust=-1.2,size=2.5)+
   geom_hline(aes(yintercept=.95), colour="blue", linetype="dashed")+
   #geom_vline(aes(xintercept=xInt), colour="blue", linetype="dashed")+
   #geom_text(data=subset(result.df, pVal > 0.05 & log2(abundance) > xInt),alpha=.5,hjust=.65, vjust=-1.2,size=2)+
   #geom_text(data=subset(result.df, pVal < 0.05 & log2(abundance) < xInt),alpha=.5,hjust=.65, vjust=-1.2,size=2)+
   theme_classic() + 
   scale_size(range=c(2,12),expand=c(2,0),breaks=c(0,1,10,100,1000,1000000),labels=c(">=0",">=1",">=10",">=100",">=1000",">=1000000"),guide="legend")

正如您所看到的,介绍了断点并将其标记为强制。但是,图例中的点大小不会反映图中的点大小。知道如何解决这个问题吗?

1 个答案:

答案 0 :(得分:1)

正如@Roman所提到的,如果你使用scale_size,你可以指定大小的限制..

以下是如何控制点数大小的示例

result.df = read.table(text = 'orgaName                  abundance          pVal         score        
A                        3          9.998622e-01     1.795338e-04
B                        2          9.999790e-01     1.823428e-05
C                        1          2.225074e-308    3.076527e+02
D                        1          3.510957e-01     4.545745e-01
E                        3          2.510957e-01     2.545745e+00
F                        3          1.510957e-02     2.006527e+02
G                        2          5.510957e-01     3.545745e-02', header = T)

library(ggplot2)
ggplot(result.df, aes(log2(abundance), (1-pVal), label=orgaName)) +
  ylab("1 - P-Value")+
  xlab("log2(abundance)")+
  geom_point(aes(size=score))+
  #ggtitle(colnames(case.count.matrix)[i])+
  geom_text(data=subset(result.df, pVal < 0.05),hjust=.65, vjust=-1.2,size=2.5)+       
  geom_hline(aes(yintercept=.95), colour="blue", linetype="dashed")+
  theme_classic() + 
  scale_size(range = c(2,12))

输出图是 enter image description here