Wednesday, January 18, 2023

Bar Graph With three factora data

 


p_nitrogen=ggplot(data=mean_flux ,aes(x=day, y=nitrogen,

                                         fill=factor(Fertilizer.type) )) +  theme_bw() +

  geom_bar(width=pos,position=position_dodge(pos),stat="identity")+

  geom_errorbar(aes(ymin=mean_flux$nitrogen-sd_flux$nitrogen,ymax=mean_flux$nitrogen+sd_flux$nitrogen),

                width=pos/2,

                position=position_dodge(pos))+

  #geom_line(aes(color = Fertilizer.type), position = position_dodge(width = 1))+

  xlab(labs$no) +

  ylab(labs$nitrogenn)+

  scale_fill_manual(values=c("red", "blue", "green","grey", "yellow"))+

  #scale_fill_brewer(palette="BrBG") + # color adjustment

  s.theme1+ # add x and y axis theme here

  s.theme2+ # add-legend theme here

  facet +    # third factor

  facect.t + # facet adjustment

  scale_y_continuous(limits = c(0, 4.00), breaks = seq(0, 4.00, by = 0.5))+

  scale_x_continuous(breaks=c(1,4,6,8,11,14,18,20,22,25,27,29,32,34,36,39,41,43,46,49,53,55,57,60,62,64,67))+

  theme(legend.position = "top")+ # facet adjustment

  labs(fill = "Fertilizer type") # correct legend title

p_nitrogen 

ggsave("p_nitrogen-bar0001.png", width = 20, height =10)

No comments:

Post a Comment