Advertisement
OreganoHauch

R wieder toll

Mar 14th, 2023
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.73 KB | None | 0 0
  1. setwd("C:/Users/Jan/Documents/R/")
  2. install.packages("readr")
  3. library(readr)
  4. install.packages("ggplot2")
  5. library(ggplot2)
  6. install.packages("openxlsx")
  7. library(openxlsx)
  8.  
  9. ##### BODENPROBEN #####
  10. bodenproben = read.xlsx("C:/Users/user/Documents/R/Boden Paysan.xlsx", sheet = "alle_werte")
  11. boden_r_a = read.xlsx("C:/Users/user/Documents/R/Boden Paysan.xlsx", sheet = "r. acetosa")
  12. boden_d_g = read.xlsx("C:/Users/user/Documents/R/Boden Paysan.xlsx", sheet = "d. glomerata")
  13. boden_a_p = read.xlsx("C:/Users/user/Documents/R/Boden Paysan.xlsx", sheet = "a. pratensis")
  14. boden_a_s = read.xlsx("C:/Users/user/Documents/R/Boden Paysan.xlsx", sheet = "a. sylvestris")
  15. boden_r_o = read.xlsx("C:/Users/user/Documents/R/Boden Paysan.xlsx", sheet = "r. obtusifolius")
  16.  
  17.  
  18. ##### mittlere Nährstoffwerte pro Zielart #####
  19. pH_r_a = mean(boden_r_a [,8])
  20. p1_r_a = mean(boden_r_a [,2])
  21.  
  22. p2_r_a = mean(boden_r_a [,3])
  23.  
  24. k1_r_a = mean(boden_r_a [,4])
  25.  
  26. k2_r_a = mean(boden_r_a [,5])
  27.  
  28. mg1_r_a = mean(boden_r_a [,6])
  29.  
  30. mg2_r_a = mean(boden_r_a [,7])
  31.  
  32.  
  33.  
  34. pH_d_g = mean(boden_d_g [,8])
  35.  
  36. p1_d_g = mean(boden_d_g [,2])
  37.  
  38. p2_d_g = mean(boden_d_g [,3])
  39.  
  40. k1_d_g = mean(boden_d_g [,4])
  41. k2_d_g = mean(boden_d_g [,5])
  42. mg1_d_g = mean(boden_d_g [,6])
  43. mg2_d_g = mean(boden_d_g [,7])
  44.  
  45.  
  46. pH_a_p = mean(boden_a_p [,8])
  47.  
  48. p1_a_p = mean(boden_a_p [,2])
  49.  
  50. p2_a_p = mean(boden_a_p [,3])
  51.  
  52. k1_a_p = mean(boden_a_p [,4])
  53.  
  54. k2_a_p = mean(boden_a_p [,5])
  55.  
  56. mg1_a_p = mean(boden_a_p [,6])
  57.  
  58. mg2_a_p = mean(boden_a_p [,7])
  59.  
  60.  
  61.  
  62. pH_a_s = mean(boden_a_s [,8])
  63.  
  64. p1_a_s = mean(boden_a_s [,2])
  65.  
  66. p2_a_s = mean(boden_a_s [,3])
  67.  
  68. k1_a_s = mean(boden_a_s [,4])
  69.  
  70. k2_a_s = mean(boden_a_s [,5])
  71.  
  72. mg1_a_s = mean(boden_a_s [,6])
  73.  
  74. mg2_a_s = mean(boden_a_s [,7])
  75.  
  76.  
  77.  
  78. pH_r_o = mean(boden_r_o [,8])
  79.  
  80. p1_r_o = mean(boden_r_o [,2])
  81.  
  82. p2_r_o = mean(boden_r_o [,3])
  83.  
  84. k1_r_o = mean(boden_r_o [,4])
  85.  
  86. k2_r_o = mean(boden_r_o [,5])
  87.  
  88. mg1_r_o = mean(boden_r_o [,6])
  89.  
  90. mg2_r_o = mean(boden_r_o [,7])
  91.  
  92.  
  93.  
  94. boden_charge1 = data.frame(matrix(nrow=5, ncol=5))
  95.  
  96. colnames(boden_charge1) = c("Zielart", "P", "K", "Mg", "pH")
  97.  
  98. boden_charge1[,1] = c("Rumex acetosa", "Dactylis glomerata", "Alopecurus pratensis", "Anthriscus sylvestris", "Rumex obtusifolius")
  99.  
  100. boden_charge1[,2] = c(p1_r_a, p1_d_g, p1_a_p, p1_a_s, p1_r_o)
  101.  
  102. boden_charge1[,3] = c(k1_r_a, k1_d_g, k1_a_p, k1_a_s, k1_r_o)
  103.  
  104. boden_charge1[,4] = c(mg1_r_a, mg1_d_g, mg1_a_p, mg1_a_s, mg1_r_o)
  105.  
  106. boden_charge1[,5] = c(pH_r_a, pH_d_g, pH_a_p, pH_a_s, pH_r_o)
  107.  
  108. #plot(boden_charge1[,1], type="b", main="Durchschnittliche Nährstoffwerte an Standorten der Zielarten", names= c("Rumex acetosa", "Dactylis glomerata", "Alopecurus pratensis", "Anthriscus sylvestris", "Rumex obtusifolius"), las=2)
  109.  
  110.  
  111.  
  112. #install.packages("reshape2")
  113.  
  114. #library(reshape2)
  115.  
  116. #boden_charge1test = data.frame(
  117.  
  118. # Zielart = c("Rumex acetosa", "Dactylis glomerata", "Alopecurus pratensis", "Anthriscus sylvestris", "Rumex obtusifolius"),
  119.  
  120. # P=c(p1_r_a, p1_d_g, p1_a_p, p1_a_s, p1_r_o),
  121.  
  122. #K=c(k1_r_a, k1_d_g, k1_a_p, k1_a_s, k1_r_o),
  123.  
  124. #Mg=c(mg1_r_a, mg1_d_g, mg1_a_p, mg1_a_s, mg1_r_o),
  125.  
  126. #pH=c(pH_r_a, pH_d_g, pH_a_p, pH_a_s, pH_r_o)
  127.  
  128. #)
  129.  
  130.  
  131.  
  132. #boden_charge1test$Zielart = factor(boden_charge1test$Zielart, levels = c("Rumex acetosa", "Dactylis glomerata", "Alopecurus pratensis", "Anthriscus sylvestris", "Rumex obtusifolius"))
  133.  
  134. #df_long = reshape2::melt(boden_charge1test, id.vars = "Zielart")
  135.  
  136. #ggplot(df_long, aes(x=boden_charge1test, y=value, color=variable, group=variable))+
  137.  
  138. # geom_line()+
  139.  
  140. # geom_point()+
  141.  
  142. # scale_x_discrete(limits =c("Rumex acetosa", "Dactylis glomerata", "Alopecurus pratensis", "Anthriscus sylvestris", "Rumex obtusifolius"))+
  143.  
  144. #labs(x="Zielart", y="Nährstoffe [mg/100g Substanz]")
  145.  
  146.  
  147. boden_charge1$Zielart <- factor(boden_charge1$Zielart,
  148. levels = c("Rumex acetosa", "Dactylis glomerata",
  149. "Alopecurus pratensis", "Anthriscus sylvestris",
  150. "Rumex obtusifolius"))
  151.  
  152. ggplot(boden_charge1, aes(x = Zielart, group = 1)) +
  153. geom_point(aes(y = P, color = "1")) +
  154. geom_line(aes(y = P, color = "1"), linetype = 1, size = 1) +
  155. geom_point(aes(y = K, color = "2")) +
  156. geom_line(aes(y = K, color = "2"), linetype = 1, size = 1) +
  157. geom_point(aes(y = Mg, color = "3")) +
  158. geom_line(aes(y = Mg, color = "3"), linetype = 1, size = 1) +
  159. labs(y = "Nährstoffe [mg/100g Substanz]",
  160. title = "Durchschnittliche Nährstoffgehälter an Standorten der Zielarten") +
  161. theme(plot.title = element_text(hjust = 0.5)) +
  162. scale_color_manual(values = c("darkgreen", "firebrick", "steelblue"),
  163. name = "Legende:",
  164. labels = c("P", "K", "Mg")) +
  165. theme(legend.position = "bottom")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement