Geom_point-将轮廓添加到用颜色渐变填充的点

时间:2020-07-28 17:08:28

标签: r ggplot2

我有一个图,我想在数据点上添加黑色轮廓。我最初使用第3行来绘制没有轮廓的数据点,并且使用第21行中详细描述的红色/蓝色刻度可以很好地绘制该图。但是,当我尝试指定形状时,可以在其中的数据点周围得到黑色轮廓第4行,我得到了黑色轮廓,但第21行中的刻度颜色没有出现。有什么办法可以使刻度线颜色保持在第21行,同时在每个点周围都具有黑色轮廓?

请参见下面的数据示例。

DOC_corr<-ggplot(ah.sub, aes(x=OC, y=HC, color=rho)) + #line1
  xlab("O/C") + ylab("H/C") + #line2
  #geom_point(aes(color=rho),alpha=1, size=3) + #line3
  geom_point(aes(fill=rho),shape=21,color="black",alpha=1, size=3) + #line4
  scale_x_continuous(breaks=c(0,0.2,0.4,0.6,0.8,1.0), #line5
                     labels=c("0","0.2","0.4","0.6","0.8","1.0"), #line6
                     limits = c(0,1)) + #line7
  scale_y_continuous(breaks=c(0,0.5,1.0,1.5,2.0), #line8
                     labels=c("0","0.5","1.0","1.5","2.0"), #line9
                     limits = c(0,2.0)) + #line10
  theme_bw() + #line11
  theme(panel.grid.major = element_blank(), #line12
        panel.grid.minor = element_blank()) + #line13
  theme(legend.position="none") + #line14
  ggtitle("a.) DOC")+ #line15
  theme(plot.title=element_text(margin=margin(t=10,b=-20),hjust=0.02))+ #line16
  geom_abline(slope=0,intercept=1.5,lty="dotdash")+ #line17
  geom_abline(intercept=1.1, slope=-0.3, lty="longdash")+ #line18
  geom_abline(intercept=0.8, slope=-0.3, lty="solid")+ #line19
  guides(color = guide_colourbar(barwidth = 20, barheight = 1, title = NULL)) + #line20
  scale_color_gradient2(low="dodgerblue2", mid="white",high="firebrick2", midpoint = 0) #line21

Example of data
                    rho         p               HC          OC
C10H11O10N0S0.C13_0 0.4902728   0.0090747398    1.1000000   1.0000000
C10H11O8N0S0.C13_0  0.4740260   0.0121590558    1.1000000   0.8000000
C10H11O9N0S0.C13_0  0.5604047   0.0022254292    1.1000000   0.9000000
C10H13O8N0S0.C13_0  0.4435216   0.0205314496    1.3000000   0.8000000
C10H13O9N0S0.C13_0  0.4333007   0.0241609448    1.3000000   0.9000000
C10H5O8N0S0.C13_0   0.3865902   0.0494659226    0.5000000   0.8000000
C10H6O5N3S0.C13_0   -0.4082811  0.0357124055    0.6000000   0.5000000
C10H6O6N3S0.C13_0   -0.4746872  0.0120226831    0.6000000   0.6000000
C10H7O4N0S0.C13_0   0.4252652   0.0273899584    0.7000000   0.4000000
C10H7O7N0S1.C13_0   0.4250982   0.0274615412    0.7000000   0.7000000

0 个答案:

没有答案