2016-03-15 150 views
-1

我在ggplot2中创建了一个图(见下文)。我还没有想出如何将颜色更改为灰度(移植=是或否,颜色应该是黑色和深灰色),在符号周围带有黑色边框。这将包括符号和错误栏,并应适用于图例。R ggplot2如何更改符号颜色?

如何在符号周围添加黑色边框?我试着将pch=21添加到geomplot行,但是搞砸了颜色。

下面是阴谋代码:

# create personal theme for ggplot 
my_theme<- theme_grey() + theme(legend.key = element_blank(),axis.text=element_text(size=14),axis.text=element_text(size=14), 
       axis.title=element_text(size=16,face="bold"),legend.text = element_text(size = 14), 
       legend.title = element_text(size = 16,face="bold"),legend.position="right",panel.grid.major.x = element_blank(), 
       strip.text = element_text(size = 15),plot.title = element_text(size = 14, face="bold")) 
# create plot 
ggplot(data=trans_X,aes(x=Location, y=pred,group= Substrate)) + 
    geom_line(aes(linetype= Substrate,group=Substrate),size=1)+ 
    geom_point(data=trans_X, aes(shape=transferred, group= transferred,fill=transferred,color=transferred),size=6)+ 
    geom_errorbar(data=trans_X, position=position_dodge() ,aes(ymin=pred-2*sd,ymax=pred+2*sd, color=transferred),size=0.51,width=0.1)+ 
    my_theme+ 
    scale_fill_discrete(name="Transplanted")+ 
    scale_color_manual(name="Transplanted", values = c("no" = "gray10","yes" = "gray40"))+ 
    scale_shape_discrete(name="Transplanted")+ 
    scale_linetype_manual(name="Wrackbed substrate", 
         breaks=c("Steninge","M\366lle","K\344mpinge","K\u00E5seberga"), 
         values=c(1,5,3,6))+ 
    labs(y="Predicted mean development time",x="Fly origin") 

enter image description here

+2

'?scale_color_grey'? – Jaap

+0

是的,我试过,但我得到一个错误告诉我,颜色已经设置。你能给我一个例子修改我的代码吗?谢谢! –

+0

我认为完全跛脚给一个-1没有评论?我正在努力创造一个不错的情节,并看看我的代码! –

回答

0
# create plot 
ggplot(data=trans_X,aes(x=Location, y=pred,group= Substrate)) + 
    geom_line(aes(linetype= Substrate,group=Substrate),size=1)+ 
    geom_point(data=trans_X, aes(shape=transferred, group= transferred,fill=transferred,color=transferred),size=6)+ 
    geom_errorbar(data=trans_X, position=position_dodge() ,aes(ymin=pred-2*sd,ymax=pred+2*sd, color=transferred),size=0.51,width=0.1)+ 
    my_theme + 
    scale_shape_manual(name="Transplanted", values=c(21,24))+ 
    scale_colour_manual(name="Transplanted", values = c("no" = "black","yes" = "black")) + 
    scale_fill_manual(name="Transplanted", values = c("no" = "black","yes" = "gray60"))+ 
    scale_linetype_manual(name="Wrackbed substrate", 
         breaks=c("Steninge","M\366lle","K\344mpinge","K\u00E5seberga"), 
         values=c(1,5,3,6))+ 
    labs(y="Predicted mean development time",x="Fly origin") 

enter image description here

1

当您设置scale_colour_grey()然后设置scale_color_discrete(),你的第一个色标(灰色)被消除,并与新的代替(离散)。所以我认为你想要做的是从你的代码中删除scale_color_discrete(),并在scale_colour_grey()行内添加name = "Transplanted"

+0

谢谢!我们融合在同一个解决方案中。我添加了'scale_colour_manual(name =“Transplanted”,values = c(“no”=“DarkGray”,“yes”=“Black”))+'替换'scale_color_discrete'。现在我只想弄清楚如何在符号周围添加黑色边框! –