如何放置小饼图以在geom_point中分配不同的变量?

时间:2018-10-21 16:03:11

标签: r ggplot2

我有一个名为test1.melted的数据框。第一列包含稀释的样本(及其比例),这些样本总体上使图中的每个geom_point都具有下面的代码。 我想根据绘图中各点的比例用两种不同的颜色显示每个点的圆比例(类似这样:ggplot use small pie charts as points with geom_point,但我想使用彩色饼图并在图例中显示这些变量。然后,我不想显示图中的每个geom_point的名称(就像现在一样)。谢谢!

数据:

test1.melted<- structure(list(Wet_lab_dilution = structure(c(5L, 8L, 2L, 1L, 
3L, 4L, 5L, 8L, 7L, 6L, 3L, 4L, 5L, 8L, 2L, 1L, 3L, 4L, 5L, 8L, 
7L, 6L, 3L, 4L), .Label = c(" 20% NA12878 + 80% NA12877", " 25% NA12878 + 75% NA12877", 
"10% NA12878 + 90% NA12877", "100% NA12877", "100% NA12878", 
"20% NA12878 + 80% NA12877", "25% NA12878 + 75% NA12877", "50% NA12878 + 50% NA12877"
), class = "factor"), ING = c(1.02, 0.619, 0.294, 0.244, 0.134, 
0.003, 0.003, 0.697, 0.964, 0.978, 1, 1, 1.02, 0.619, 0.294, 
0.244, 0.134, 0.003, 0.003, 0.697, 0.964, 0.978, 1, 1), variable = structure(c(1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("tEst", "pair"), class = "factor"), 
    value = c(0.1, 59.8, 84.6, 89.2, 97.4, 100, 99.6, 56.4, 29.9, 
    24, 12.1, 0.1, 0.1, 51.08, 75.28, 80.09, 90.16, 100, 100, 
    48.09, 23.97, 18.81, 9.24, 0.08)), row.names = c(NA, -24L
), .Names = c("Wet_lab_dilution", "ING", "variable", "value"), class = "data.frame")

代码:

p = ggplot(test1.melted,
           aes(x = value,
               y = ING))+
  facet_grid( ~ variable)

p <- p + geom_point(size=2)+geom_text(aes(label=Wet_lab_dilution),hjust= 0, vjust=2,size=4)+
  scale_x_continuous(breaks=c( 0,50, 100),
                     limits=c(0, 100) )
p<- p+labs( x="Predicted contamination (%)", y="ING",color = "Pairs:") +
  theme_bw(base_size=14) +theme(panel.border = element_rect(), panel.grid.major = element_blank(),
                                panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  theme(axis.text.x=element_text(size=12), axis.title.x=element_text(size=14),
        axis.text.y=element_text(size=12), axis.title.y=element_text(size=14),
        plot.title=element_text(size=12, face = "bold", color= "black"),
        panel.grid.minor = element_blank(),
        strip.text.x = element_text(size = 14, colour = "black", angle = 0),
        legend.position ='bottom',
        legend.text=element_text(size=12))
p + guides(shape = guide_legend(override.aes = list(size = 5)))

0 个答案:

没有答案