ggplot:手动绘制图例,而不是自动重新调整绘图大小

时间:2014-03-10 23:16:08

标签: r ggplot2 legend

我想绘制一个图,我可以在图表中确定图表的大小。到目前为止,这就是我对代码的要求:

library(ggplots2)

overlap <- read.delim("/R_plots/num_ins_vs_overlap.txt", sep="\t", row.names=1, header=TRUE)

tools <- overlap$tools
window <- overlap$window
numVars <- overlap$number_of_variants
olPcnt <- overlap$pcnt_overlap
shape <- overlap$shape

s <- qplot(numVars, olPcnt, data=overlap, colour=tools, size=window, shape=shape)

s + scale_shape(solid=FALSE) + labs(title="Number of Variants Detected vs. % Overlap", x="Number of Variants Detected", y="% Overlap")

数据本身如下所示:

        tools   window  number_of_variants      pcnt_overlap    shape
1       scalpel 5       184458  38.32   circle
2       pindel  5       320770  32.42   circle
3       samtools        5       313147  34.16   circle
4       UnifiedGenotyper        5       234746  36.98   circle
5       scalpel 20      184458  39.33   circle
6       pindel  20      320770  33.10   circle
7       samtools        20      313147  35.18   circle
8       UnifiedGenotyper        20      234746  38.38   circle
9       scalpel 50      184458  39.83   circle
10      pindel  50      320770  32.92   circle
11      samtools        50      313147  35.91   circle
12      UnifiedGenotyper        50      234746  39.16   circle
13      scalpel 100     184458  40.34   circle
14      pindel  100     320770  32.74   circle
15      samtools        100     313147  37.49   circle
16      UnifiedGenotyper        100     234746  48.66   circle

窗口区域有4个不同的值:(5,20,50和100),我希望这些是图形的大小......看起来我根据我所看到的那样得到了那个部分在情节上。问题在于图例,我看到(25,50,75和100的尺寸)。有没有办法告诉脚本不要在图例上改变这种尺寸,而是显示图的实际尺寸?

提前致谢,

1 个答案:

答案 0 :(得分:1)

尝试将window作为一个因素:

s <- qplot(numVars, olPcnt, data=overlap, 
           colour=tools, 
           size=as.factor(window), shape=shape)