Saturday, January 7, 2023

Three factor bar graph in R

 





p_nitrate =ggplot(data=mean_soil ,aes(x=Depth, y=nitrate ,

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

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

  geom_errorbar(aes(ymin=mean_soil$nitrate -sd_soil$nitrate ,ymax=mean_soil$nitrate +sd_soil$nitrate ),

                width=pos/2,

                position=position_dodge(pos))+

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

  xlab("Soil depths") +

  ylab(labs$nitrate )+

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

  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, 1.5), breaks = seq(0, 15, by = 0.3))+

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

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

p_nitrate  

ggsave("soil_nitrate .png", width = 20, height =10)


No comments:

Post a Comment