首页 文章

R ggplot2如何改变符号颜色?

提问于
浏览
-1

我在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 回答

  • 0

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

  • 1
    # 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

相关问题