Larousse24 / Larousse24-ag-problems-semester

Summer 2020/Data Carpentry for Agroecologists
0 stars 0 forks source link

Graphs for presentation #12

Closed Larousse24 closed 3 years ago

Larousse24 commented 3 years ago

Hi @brymz I added the codes that I used to get the graphs and the dataset so that you can take a look at them.

library(agricolae) library(dplyr) library(ggplot2) library(tidyverse) data<-TREC_Litterbags_p LB_new<-data %>% group_by(CropTrt, Day) %>% mutate(CNratio =(C_pct/N_pct), Nmin = (Final_g_dry(N_pct)), Cmin = (Final_g_dry(C_pct)), N_pct_loss = (Final_g_dry(N_pct))/Stuffed_g_N, C_pct_loss = (Final_g_dry(C_pct))/Stuffed_g_C, N_g_loss = (Stuffed_g_N-(Final_g_dry(N_pct)))/Stuffed_g_N, C_g_loss = (Stuffed_g_C-(Final_g_dry(C_pct)))/Stuffed_g_C, DM_pct = (Stuffed_g_dry-Final_g_dry)/Stuffed_g_dry, se_N = (sd(N_pct)/sqrt(4)), se_C = (sd(C_pct)/sqrt(4)), se_CN = (sd(CNratio)/sqrt(4)), se_Nmin = (sd(Nmin)/sqrt(4)), se_Cmin = (sd(Cmin)/sqrt(4)), se_DM = (sd(Final_g_dry)/sqrt(4)), se_N_g_loss = (sd(N_g_loss)/sqrt(4)), se_C_g_loss = (sd(C_g_loss)/sqrt(4)), se_DM_pct = (sd(DM_pct)/sqrt(4)))%>% summarize(avg_ash = mean(Ash_Pct), avg_N = mean(N_pct), avg_C = mean(C_pct), avg_DM = mean(Final_g_dry), avg_DM_pct = mean(DM_pct), avg_fresh = mean(Stuffed_g_fresh), avg_Nmin = mean(Nmin), avg_Cmin = mean(Cmin), avg_CN = mean(CNratio), avgCpct = mean(C_pct_loss), avgNpct = mean(N_pct_loss), avg_Nloss = mean(N_g_loss), avg_Closs = mean(C_g_loss), se_CN = mean(se_CN), se_C = mean(se_C), se_N = mean(se_N), se_Nmin = mean(se_Nmin), se_Cmin = mean(se_Cmin), se_DM = mean(se_DM), se_Nloss = mean(se_N_g_loss), se_Closs = mean(se_C_g_loss), se_DM_pct = mean(se_DM_pct))

N remaining ggplot(LB_new, aes(x=Day, y=avg_Nmin, color=CropTrt)) + scale_color_manual(values=c("#A93226", "#D4AC0D", "#85C1E9", "#AF601A", "#8E44AD", "#196F3D")) + geom_point(alpha=0.5, size=2) + theme_bw(base_size = 12, base_family = "Helvetica")+ geom_errorbar(aes(ymin=avg_Nmin-2se_Nmin, ymax=avg_Nmin+2se_Nmin), width=0.2) + geom_line(size=1) + ggsave("file_name.png", width = 3, height = 3, unit = "in") + scale_x_continuous(breaks = round(seq(min(LB_new$Day), max(LB_new$Day), by = 7),1))+ labs(y="N Remaining (kg/ha)", x="Days After Placement (DAP)", color = "Residues")+ theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())

C remaining ggplot(LB_new, aes(x=Day, y=avg_Cmin, color=CropTrt)) + scale_color_manual(values=c("#A93226", "#D4AC0D", "#85C1E9", "#AF601A", "#8E44AD", "#196F3D")) + geom_point(alpha=0.5, size=2) + theme_bw(base_size = 12, base_family = "Helvetica")+ geom_errorbar(aes(ymin=avg_Cmin-2se_Cmin, ymax=avg_Cmin+2se_Cmin), width=0.2) + geom_line(size=1) + ggsave("file_name.png", width = 3, height = 3, unit = "in") + scale_x_continuous(breaks = round(seq(min(LB_new$Day), max(LB_new$Day), by = 7),1))+ labs(y="C Remaining(kg/ha)", x="Days After Placement (DAP)", color = "Ratios")+ theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())

DM decomposition ggplot(LB_new, aes(x=Day, y=avg_DM, color=CropTrt)) + scale_color_manual(values=c("#A93226", "#D4AC0D", "#85C1E9", "#AF601A", "#8E44AD", "#196F3D")) + geom_point(alpha=0.5, size=2) + theme_bw(base_size = 12, base_family = "Helvetica") + geom_errorbar(aes(ymin=avg_DM-2se_DM, ymax=avg_DM+2se_DM), width=0.2) + geom_line(size=0.3) + ggsave("file_name.png", width = 3, height = 3, unit = "in") + scale_x_continuous(breaks = round(seq(min(LB_new$Day), max(LB_new$Day), by = 7),1))+ labs(y="DM Remaining (g)", x="Days After Placement (DAP)") + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())

brymz commented 3 years ago

Looking at the code and TREC_Litterbags_Results.csv...

Larousse24 commented 3 years ago

I uploaded a dataset named "TREC_Litterbag_p on this repository.

Larousse24 commented 3 years ago

Also, I would like to create a graph explaining the baseline residue for N and C content in R with following codes. How can I do that?

ANOVAs per Day

data <- read.csv("TREC_Litterbags_snn.csv") LB_new<-data for(i in unique(LB_new$Day)){ LB_days<- LB_new %>% filter(Day == i)

LBaov2<-aov(N_pct~CropTrt, data=LB_days) print(paste(i, "- %N")) print(summary(LBaov2)) print(HSD.test(LBaov2, "CropTrt")$groups)

LBaov2<-aov(C_pct~CropTrt, data=LB_days) print(paste(i, "- %C")) print(summary(LBaov2)) print(HSD.test(LBaov2, "CropTrt")$groups)

brymz commented 3 years ago

Oh, ok. I am surprised that you shifted your materials from the Litterbags repository to this repo (Larousse24-ag-problems-semester).

To build a table from these results you would have to establish a new data.frame to which you place the results after extracting them from the analysis. For example:

Again, I don't see the data file TREC_Litterbags_snn.csv.

Everything (data and code) needs to be organized and in the same place. The raw data should be the starting place for all of your calculations and analysis. Calculations and analysis should be made in the code. Intermediate data files should be avoided whenever possible.

brymz commented 3 years ago

How is it that you have a Final_g_dry that is more than the Stuffed_g_fresh?? This happens throughout the data.

Larousse24 commented 3 years ago

I will upload my materials on the Litterbags repository. I just need to make sure that everything is set and I don't have to make any changes in data anymore before I do that.

This is the formula that I used to get the Final_g_dry, " Final_g_dry = Final_dry_wash*(1-(Ash_pct/100)))". It just takes the ash content out of the field dry weights.

brymz commented 3 years ago

So the question becomes how is Final_dry_wash greater than Stuffed_g_fresh? Also, are the Final_dry_wash values supposed to be integers? Where is the raw data from the analytical lab??

I disagree with your statement about making sure "everything is set" before entering into the repository. The whole point is that the repository is a location for your working files so that each change to the data and code can be logged through the version control system.

Larousse24 commented 3 years ago

Unfortunately, I did not think of it that way. I am gonna switch to the litterbags repository. They are integers because of the scale I used to weigh the residues when I removed them from field. I have the raw from the analytical lab, Do I need to upload it? Stuffed_g_fresh is not the initial fresh weight of the residue. I am trying to figure out what makes it greater cause I did not think of that before.