softwareDevelopment commited on
Commit
cb70ece
·
verified ·
1 Parent(s): 7bbf135

Update app.R

Browse files
Files changed (1) hide show
  1. app.R +201 -82
app.R CHANGED
@@ -21,6 +21,8 @@ library(moments)
21
  library(reshape2)
22
  library(gridExtra)
23
  library(openxlsx)
 
 
24
 
25
  # ─────────────────────────────────────────────────────────────────
26
  # UI
@@ -691,21 +693,35 @@ server <- function(input, output, session) {
691
  tryCatch({
692
  df <- working_data() %>%
693
  select(Environment, Genotype, all_of(trait)) %>%
694
- rename(Value=!!trait) %>% filter(!is.na(Value))
 
 
 
 
 
 
 
 
695
  p <- ggplot(df, aes(x=Environment, y=Value, fill=Environment)) +
696
  geom_boxplot(alpha=0.7, outlier.colour="red", outlier.size=2) +
697
- geom_jitter(aes(color=Genotype), width=0.2, alpha=0.4, size=1) +
698
  labs(title=paste("Boxplot of", trait, "per Environment"),
699
- x="Environment", y=trait) +
700
  theme_minimal() +
701
- theme(axis.text.x=element_text(angle=45, hjust=1),
702
- axis.text=element_text(color="#000"),
703
- axis.title=element_text(color="#000"),
704
- plot.title=element_text(color="#000"),
705
- legend.position="none") +
706
- scale_fill_manual(values=get_color_palette(rv$color_scheme,
707
- length(unique(df$Environment))))
708
- ggplotly(p, height=rv$plot_height, width=rv$plot_width)
 
 
 
 
 
 
709
  }, error=function(e) { showNotification(e$message, type="error"); NULL })
710
  })
711
 
@@ -717,22 +733,36 @@ server <- function(input, output, session) {
717
  tryCatch({
718
  df <- working_data() %>%
719
  select(Environment, all_of(trait)) %>%
720
- rename(Value=!!trait) %>% filter(!is.na(Value))
 
 
 
 
 
 
 
 
721
  p <- ggplot(df, aes(x=Environment, y=Value, fill=Environment)) +
722
  geom_violin(alpha=0.7, trim=FALSE) +
723
- geom_boxplot(width=0.1, fill="white", alpha=0.8) +
724
- stat_summary(fun=mean, geom="point", shape=18, size=3, color="#1E3A8A") +
725
  labs(title=paste("Violin Plot of", trait, "per Environment"),
726
- x="Environment", y=trait) +
727
  theme_minimal() +
728
- theme(axis.text.x=element_text(angle=45, hjust=1),
729
- axis.text=element_text(color="#000"),
730
- axis.title=element_text(color="#000"),
731
- plot.title=element_text(color="#000"),
732
- legend.position="none") +
733
- scale_fill_manual(values=get_color_palette(rv$color_scheme,
734
- length(unique(df$Environment))))
735
- ggplotly(p, height=rv$plot_height, width=rv$plot_width)
 
 
 
 
 
 
736
  }, error=function(e) { showNotification(e$message, type="error"); NULL })
737
  })
738
 
@@ -793,18 +823,31 @@ server <- function(input, output, session) {
793
  req(env_means_data())
794
  df <- env_means_data()
795
  tryCatch({
 
 
 
 
 
796
  p <- ggplot(df, aes(x=reorder(Genotype, Mean), y=Mean, fill=Environment)) +
797
  geom_col(position="dodge", alpha=0.85) +
798
  coord_flip() +
799
  labs(title=paste("Genotype Means per Environment —", input$selected_trait),
800
- x="Genotype", y="Mean Value") +
801
  theme_minimal() +
802
- theme(axis.text=element_text(color="#000"),
803
- axis.title=element_text(color="#000"),
804
- plot.title=element_text(color="#000")) +
 
 
 
 
 
805
  scale_fill_manual(values=get_color_palette(rv$color_scheme,
806
- length(unique(df$Environment))))
807
- ggplotly(p, height=rv$plot_height, width=rv$plot_width)
 
 
 
808
  }, error=function(e) { showNotification(e$message, type="error"); NULL })
809
  })
810
 
@@ -844,20 +887,40 @@ server <- function(input, output, session) {
844
  req(env_rank_data())
845
  df <- env_rank_data()$long
846
  tryCatch({
847
- p <- ggplot(df, aes(x=Environment, y=Rank, color=Genotype, group=Genotype)) +
848
- geom_line(size=1, alpha=0.8) +
849
- geom_point(size=3, alpha=0.9) +
850
- scale_y_reverse(breaks=1:length(unique(df$Genotype))) +
 
 
 
 
 
 
 
 
 
 
 
 
851
  labs(title=paste("Genotype Rank Across Environments —", input$selected_trait),
852
- x="Environment", y="Rank (1 = Best)") +
853
  theme_minimal() +
854
- theme(axis.text.x=element_text(angle=45, hjust=1),
855
- axis.text=element_text(color="#000"),
856
- axis.title=element_text(color="#000"),
857
- plot.title=element_text(color="#000")) +
858
- scale_color_manual(values=get_color_palette(rv$color_scheme,
859
- length(unique(df$Genotype))))
860
- ggplotly(p, tooltip=c("color","x","y"), height=rv$plot_height, width=rv$plot_width)
 
 
 
 
 
 
 
 
861
  }, error=function(e) { showNotification(e$message, type="error"); NULL })
862
  })
863
 
@@ -949,21 +1012,33 @@ server <- function(input, output, session) {
949
  req(env_blues_data())
950
  df <- env_blues_data()
951
  tryCatch({
 
 
 
 
 
 
952
  p <- ggplot(df, aes(x=reorder(Genotype, BLUE), y=BLUE, color=Environment)) +
953
- geom_point(size=3, alpha=0.8) +
954
- geom_errorbar(aes(ymin=BLUE-SE, ymax=BLUE+SE), width=0.3, alpha=0.7) +
955
- facet_wrap(~Environment, scales="free_x") +
956
  coord_flip() +
957
  labs(title=paste("Within-Environment BLUEs —", input$selected_trait),
958
- x="Genotype", y="BLUE") +
959
  theme_minimal() +
960
- theme(axis.text=element_text(color="#000"),
961
- axis.title=element_text(color="#000"),
962
- plot.title=element_text(color="#000"),
963
- legend.position="none") +
964
- scale_color_manual(values=get_color_palette(rv$color_scheme,
965
- length(unique(df$Environment))))
966
- ggplotly(p, height=rv$plot_height, width=rv$plot_width)
 
 
 
 
 
 
967
  }, error=function(e) { showNotification(e$message, type="error"); NULL })
968
  })
969
 
@@ -1021,23 +1096,37 @@ server <- function(input, output, session) {
1021
  req(working_data(), input$selected_trait)
1022
  if (!input$selected_trait %in% rv$traits) return(NULL)
1023
  tryCatch({
1024
- p <- working_data() %>%
1025
  select(Genotype, Environment, all_of(input$selected_trait)) %>%
1026
  rename(Value=!!input$selected_trait) %>% filter(!is.na(Value)) %>%
 
 
 
 
 
 
 
 
1027
  ggplot(aes(x=Environment, y=Value, fill=Environment)) +
1028
  geom_boxplot(alpha=0.7) +
1029
- geom_jitter(aes(color=Genotype), width=0.2, alpha=0.5, size=1) +
1030
  labs(title=paste("Distribution of", input$selected_trait, "by Environment"),
1031
- x="Environment", y=input$selected_trait) +
1032
  theme_minimal() +
1033
- theme(axis.text.x=element_text(angle=45, hjust=1),
1034
- axis.text=element_text(color="#000"),
1035
- axis.title=element_text(color="#000"),
1036
- plot.title=element_text(color="#000"),
1037
- legend.position="none") +
1038
- scale_fill_manual(values=get_color_palette(rv$color_scheme,
1039
- length(unique(working_data()$Environment))))
1040
- ggplotly(p, height=rv$plot_height, width=rv$plot_width)
 
 
 
 
 
 
1041
  }, error=function(e) { showNotification(e$message, type="error"); NULL })
1042
  })
1043
 
@@ -1162,19 +1251,34 @@ server <- function(input, output, session) {
1162
  output$blues_plot <- renderPlotly({
1163
  req(mixed_model_analysis())
1164
  tryCatch({
1165
- df <- mixed_model_analysis()$blues
 
 
 
 
 
 
 
1166
  p <- ggplot(df, aes(x=Environment, y=BLUE, color=Genotype, group=Genotype)) +
1167
  geom_line(linewidth=1) + geom_point(size=2) +
1168
  labs(title=paste("BLUEs for", input$selected_trait),
1169
- x="Environment", y="BLUE") +
1170
  theme_minimal() +
1171
- theme(axis.text.x=element_text(angle=45, hjust=1),
1172
- axis.text=element_text(color="#000"),
1173
- axis.title=element_text(color="#000"),
1174
- plot.title=element_text(color="#000")) +
1175
- scale_color_manual(values=get_color_palette(rv$color_scheme,
1176
- length(unique(df$Genotype))))
1177
- ggplotly(p, tooltip=c("color","x","y"), height=rv$plot_height, width=rv$plot_width)
 
 
 
 
 
 
 
 
1178
  }, error=function(e) { showNotification(e$message, type="error"); NULL })
1179
  })
1180
 
@@ -1525,20 +1629,35 @@ server <- function(input, output, session) {
1525
  output$ammi_plot <- renderPlotly({
1526
  req(stability_analysis())
1527
  tryCatch({
1528
- ad <- stability_analysis()$ammi_data
 
 
 
 
 
 
 
1529
  p <- ggplot(ad, aes(x=Environment, y=Mean_Value,
1530
  color=Genotype, group=Genotype)) +
1531
  geom_line(linewidth=1) + geom_point(size=2) +
1532
  labs(title=paste("G×E Interaction —", input$selected_trait),
1533
- x="Environment", y="Mean Value") +
1534
  theme_minimal() +
1535
- theme(axis.text.x=element_text(angle=45, hjust=1),
1536
- axis.text=element_text(color="#000"),
1537
- axis.title=element_text(color="#000"),
1538
- plot.title=element_text(color="#000")) +
1539
- scale_color_manual(values=get_color_palette(rv$color_scheme,
1540
- length(unique(ad$Genotype))))
1541
- ggplotly(p, tooltip=c("color","x","y"), height=rv$plot_height, width=rv$plot_width)
 
 
 
 
 
 
 
 
1542
  }, error=function(e) { showNotification(e$message, type="error"); NULL })
1543
  })
1544
 
@@ -1710,4 +1829,4 @@ server <- function(input, output, session) {
1710
 
1711
  } # end server
1712
 
1713
- shinyApp(ui=ui, server=server)
 
21
  library(reshape2)
22
  library(gridExtra)
23
  library(openxlsx)
24
+ library(stringr)
25
+ library(scales)
26
 
27
  # ─────────────────────────────────────────────────────────────────
28
  # UI
 
693
  tryCatch({
694
  df <- working_data() %>%
695
  select(Environment, Genotype, all_of(trait)) %>%
696
+ rename(Value=!!trait) %>% filter(!is.na(Value)) %>%
697
+ mutate(Environment = factor(Environment))
698
+
699
+ n_env <- length(unique(df$Environment))
700
+ lbl_angle <- if (n_env > 6) 90 else if (n_env > 3) 45 else 0
701
+ lbl_hjust <- if (lbl_angle == 90) 1 else if (lbl_angle == 45) 1 else 0.5
702
+ lbl_vjust <- if (lbl_angle == 90) 0.5 else 1
703
+ bot_margin <- if (lbl_angle >= 45) 60 else 20
704
+
705
  p <- ggplot(df, aes(x=Environment, y=Value, fill=Environment)) +
706
  geom_boxplot(alpha=0.7, outlier.colour="red", outlier.size=2) +
707
+ geom_jitter(width=0.2, alpha=0.35, size=0.8, color="#444444") +
708
  labs(title=paste("Boxplot of", trait, "per Environment"),
709
+ x=NULL, y=trait) +
710
  theme_minimal() +
711
+ theme(
712
+ axis.text.x = element_text(angle=lbl_angle, hjust=lbl_hjust,
713
+ vjust=lbl_vjust, size=11, color="#000"),
714
+ axis.text.y = element_text(size=11, color="#000"),
715
+ axis.title = element_text(size=12, color="#000"),
716
+ plot.title = element_text(size=13, color="#000", face="bold"),
717
+ plot.margin = margin(t=10, r=10, b=bot_margin, l=10),
718
+ legend.position = "none"
719
+ ) +
720
+ scale_fill_manual(values=get_color_palette(rv$color_scheme, n_env)) +
721
+ scale_x_discrete(labels = function(x) stringr::str_wrap(x, width=12))
722
+
723
+ ggplotly(p, height=rv$plot_height, width=rv$plot_width) %>%
724
+ layout(margin=list(b=bot_margin+20))
725
  }, error=function(e) { showNotification(e$message, type="error"); NULL })
726
  })
727
 
 
733
  tryCatch({
734
  df <- working_data() %>%
735
  select(Environment, all_of(trait)) %>%
736
+ rename(Value=!!trait) %>% filter(!is.na(Value)) %>%
737
+ mutate(Environment = factor(Environment))
738
+
739
+ n_env <- length(unique(df$Environment))
740
+ lbl_angle <- if (n_env > 6) 90 else if (n_env > 3) 45 else 0
741
+ lbl_hjust <- if (lbl_angle == 90) 1 else if (lbl_angle == 45) 1 else 0.5
742
+ lbl_vjust <- if (lbl_angle == 90) 0.5 else 1
743
+ bot_margin <- if (lbl_angle >= 45) 60 else 20
744
+
745
  p <- ggplot(df, aes(x=Environment, y=Value, fill=Environment)) +
746
  geom_violin(alpha=0.7, trim=FALSE) +
747
+ geom_boxplot(width=0.08, fill="white", alpha=0.85, outlier.size=1.5) +
748
+ stat_summary(fun=mean, geom="point", shape=18, size=4, color="#1E3A8A") +
749
  labs(title=paste("Violin Plot of", trait, "per Environment"),
750
+ x=NULL, y=trait) +
751
  theme_minimal() +
752
+ theme(
753
+ axis.text.x = element_text(angle=lbl_angle, hjust=lbl_hjust,
754
+ vjust=lbl_vjust, size=11, color="#000"),
755
+ axis.text.y = element_text(size=11, color="#000"),
756
+ axis.title = element_text(size=12, color="#000"),
757
+ plot.title = element_text(size=13, color="#000", face="bold"),
758
+ plot.margin = margin(t=10, r=10, b=bot_margin, l=10),
759
+ legend.position = "none"
760
+ ) +
761
+ scale_fill_manual(values=get_color_palette(rv$color_scheme, n_env)) +
762
+ scale_x_discrete(labels = function(x) stringr::str_wrap(x, width=12))
763
+
764
+ ggplotly(p, height=rv$plot_height, width=rv$plot_width) %>%
765
+ layout(margin=list(b=bot_margin+20))
766
  }, error=function(e) { showNotification(e$message, type="error"); NULL })
767
  })
768
 
 
823
  req(env_means_data())
824
  df <- env_means_data()
825
  tryCatch({
826
+ n_geno <- length(unique(df$Genotype))
827
+ txt_size <- if (n_geno > 40) 6 else if (n_geno > 20) 8 else 10
828
+ # dynamic height: give each genotype at least 18px
829
+ dyn_h <- max(rv$plot_height, n_geno * 18 + 100)
830
+
831
  p <- ggplot(df, aes(x=reorder(Genotype, Mean), y=Mean, fill=Environment)) +
832
  geom_col(position="dodge", alpha=0.85) +
833
  coord_flip() +
834
  labs(title=paste("Genotype Means per Environment —", input$selected_trait),
835
+ x=NULL, y="Mean Value") +
836
  theme_minimal() +
837
+ theme(
838
+ axis.text.y = element_text(size=txt_size, color="#000", lineheight=0.9),
839
+ axis.text.x = element_text(size=10, color="#000"),
840
+ axis.title = element_text(size=12, color="#000"),
841
+ plot.title = element_text(size=13, color="#000", face="bold"),
842
+ legend.text = element_text(size=10),
843
+ legend.title = element_text(size=11)
844
+ ) +
845
  scale_fill_manual(values=get_color_palette(rv$color_scheme,
846
+ length(unique(df$Environment)))) +
847
+ scale_x_discrete(labels=function(x) stringr::str_trunc(x, 20))
848
+
849
+ ggplotly(p, height=dyn_h, width=rv$plot_width) %>%
850
+ layout(margin=list(l=10))
851
  }, error=function(e) { showNotification(e$message, type="error"); NULL })
852
  })
853
 
 
887
  req(env_rank_data())
888
  df <- env_rank_data()$long
889
  tryCatch({
890
+ n_env <- length(unique(df$Environment))
891
+ n_geno <- length(unique(df$Genotype))
892
+ lbl_angle <- if (n_env > 6) 90 else if (n_env > 3) 45 else 0
893
+ lbl_hjust <- if (lbl_angle == 90) 1 else if (lbl_angle == 45) 1 else 0.5
894
+ lbl_vjust <- if (lbl_angle == 90) 0.5 else 1
895
+ bot_margin <- if (lbl_angle >= 45) 60 else 20
896
+ dyn_h <- max(rv$plot_height, n_geno * 14 + 120)
897
+
898
+ p <- ggplot(df, aes(x=Environment, y=Rank,
899
+ color=Genotype, group=Genotype,
900
+ text=paste0("Genotype: ", Genotype,
901
+ "<br>Rank: ", round(Rank,1),
902
+ "<br>Mean: ", round(Mean,3)))) +
903
+ geom_line(linewidth=0.9, alpha=0.75) +
904
+ geom_point(size=2.5, alpha=0.9) +
905
+ scale_y_reverse(breaks=seq(1, n_geno, by=max(1, floor(n_geno/10)))) +
906
  labs(title=paste("Genotype Rank Across Environments —", input$selected_trait),
907
+ x=NULL, y="Rank (1 = Best)") +
908
  theme_minimal() +
909
+ theme(
910
+ axis.text.x = element_text(angle=lbl_angle, hjust=lbl_hjust,
911
+ vjust=lbl_vjust, size=11, color="#000"),
912
+ axis.text.y = element_text(size=10, color="#000"),
913
+ axis.title.y = element_text(size=12, color="#000"),
914
+ plot.title = element_text(size=13, color="#000", face="bold"),
915
+ plot.margin = margin(t=10, r=10, b=bot_margin, l=10),
916
+ legend.position = if (n_geno > 25) "none" else "right",
917
+ legend.text = element_text(size=8)
918
+ ) +
919
+ scale_color_manual(values=get_color_palette(rv$color_scheme, n_geno)) +
920
+ scale_x_discrete(labels=function(x) stringr::str_wrap(x, width=10))
921
+
922
+ ggplotly(p, tooltip="text", height=dyn_h, width=rv$plot_width) %>%
923
+ layout(margin=list(b=bot_margin+20))
924
  }, error=function(e) { showNotification(e$message, type="error"); NULL })
925
  })
926
 
 
1012
  req(env_blues_data())
1013
  df <- env_blues_data()
1014
  tryCatch({
1015
+ n_geno <- length(unique(df$Genotype))
1016
+ n_env <- length(unique(df$Environment))
1017
+ txt_size <- if (n_geno > 40) 6 else if (n_geno > 20) 8 else 10
1018
+ # height grows with genotypes × environments
1019
+ dyn_h <- max(rv$plot_height, n_geno * 16 * max(1, ceiling(n_env/3)) + 120)
1020
+
1021
  p <- ggplot(df, aes(x=reorder(Genotype, BLUE), y=BLUE, color=Environment)) +
1022
+ geom_point(size=2, alpha=0.85) +
1023
+ geom_errorbar(aes(ymin=BLUE-SE, ymax=BLUE+SE), width=0.4, alpha=0.65) +
1024
+ facet_wrap(~Environment, scales="free_x", ncol=min(n_env, 3)) +
1025
  coord_flip() +
1026
  labs(title=paste("Within-Environment BLUEs —", input$selected_trait),
1027
+ x=NULL, y="BLUE") +
1028
  theme_minimal() +
1029
+ theme(
1030
+ axis.text.y = element_text(size=txt_size, color="#000", lineheight=0.9),
1031
+ axis.text.x = element_text(size=9, color="#000"),
1032
+ axis.title = element_text(size=11, color="#000"),
1033
+ strip.text = element_text(size=11, face="bold", color="#1E3A8A"),
1034
+ plot.title = element_text(size=13, color="#000", face="bold"),
1035
+ legend.position = "none"
1036
+ ) +
1037
+ scale_color_manual(values=get_color_palette(rv$color_scheme, n_env)) +
1038
+ scale_y_continuous(labels=scales::number_format(accuracy=0.01))
1039
+
1040
+ ggplotly(p, height=dyn_h, width=rv$plot_width) %>%
1041
+ layout(margin=list(l=10))
1042
  }, error=function(e) { showNotification(e$message, type="error"); NULL })
1043
  })
1044
 
 
1096
  req(working_data(), input$selected_trait)
1097
  if (!input$selected_trait %in% rv$traits) return(NULL)
1098
  tryCatch({
1099
+ df <- working_data() %>%
1100
  select(Genotype, Environment, all_of(input$selected_trait)) %>%
1101
  rename(Value=!!input$selected_trait) %>% filter(!is.na(Value)) %>%
1102
+ mutate(Environment=factor(Environment))
1103
+ n_env <- length(unique(df$Environment))
1104
+ lbl_angle <- if (n_env > 6) 90 else if (n_env > 3) 45 else 0
1105
+ lbl_hjust <- if (lbl_angle == 90) 1 else if (lbl_angle == 45) 1 else 0.5
1106
+ lbl_vjust <- if (lbl_angle == 90) 0.5 else 1
1107
+ bot_margin <- if (lbl_angle >= 45) 60 else 20
1108
+
1109
+ p <- df %>%
1110
  ggplot(aes(x=Environment, y=Value, fill=Environment)) +
1111
  geom_boxplot(alpha=0.7) +
1112
+ geom_jitter(width=0.2, alpha=0.35, size=0.8, color="#444444") +
1113
  labs(title=paste("Distribution of", input$selected_trait, "by Environment"),
1114
+ x=NULL, y=input$selected_trait) +
1115
  theme_minimal() +
1116
+ theme(
1117
+ axis.text.x = element_text(angle=lbl_angle, hjust=lbl_hjust,
1118
+ vjust=lbl_vjust, size=11, color="#000"),
1119
+ axis.text.y = element_text(size=11, color="#000"),
1120
+ axis.title = element_text(size=12, color="#000"),
1121
+ plot.title = element_text(size=13, color="#000", face="bold"),
1122
+ plot.margin = margin(t=10, r=10, b=bot_margin, l=10),
1123
+ legend.position = "none"
1124
+ ) +
1125
+ scale_fill_manual(values=get_color_palette(rv$color_scheme, n_env)) +
1126
+ scale_x_discrete(labels=function(x) stringr::str_wrap(x, width=12))
1127
+
1128
+ ggplotly(p, height=rv$plot_height, width=rv$plot_width) %>%
1129
+ layout(margin=list(b=bot_margin+20))
1130
  }, error=function(e) { showNotification(e$message, type="error"); NULL })
1131
  })
1132
 
 
1251
  output$blues_plot <- renderPlotly({
1252
  req(mixed_model_analysis())
1253
  tryCatch({
1254
+ df <- mixed_model_analysis()$blues
1255
+ n_env <- length(unique(df$Environment))
1256
+ n_gen <- length(unique(df$Genotype))
1257
+ lbl_angle <- if (n_env > 6) 90 else if (n_env > 3) 45 else 0
1258
+ lbl_hjust <- if (lbl_angle == 90) 1 else if (lbl_angle == 45) 1 else 0.5
1259
+ lbl_vjust <- if (lbl_angle == 90) 0.5 else 1
1260
+ bot_margin <- if (lbl_angle >= 45) 60 else 20
1261
+
1262
  p <- ggplot(df, aes(x=Environment, y=BLUE, color=Genotype, group=Genotype)) +
1263
  geom_line(linewidth=1) + geom_point(size=2) +
1264
  labs(title=paste("BLUEs for", input$selected_trait),
1265
+ x=NULL, y="BLUE") +
1266
  theme_minimal() +
1267
+ theme(
1268
+ axis.text.x = element_text(angle=lbl_angle, hjust=lbl_hjust,
1269
+ vjust=lbl_vjust, size=11, color="#000"),
1270
+ axis.text.y = element_text(size=11, color="#000"),
1271
+ axis.title = element_text(size=12, color="#000"),
1272
+ plot.title = element_text(size=13, color="#000", face="bold"),
1273
+ plot.margin = margin(t=10, r=10, b=bot_margin, l=10),
1274
+ legend.position = if (n_gen > 25) "none" else "right",
1275
+ legend.text = element_text(size=8)
1276
+ ) +
1277
+ scale_color_manual(values=get_color_palette(rv$color_scheme, n_gen)) +
1278
+ scale_x_discrete(labels=function(x) stringr::str_wrap(x, width=10))
1279
+
1280
+ ggplotly(p, tooltip=c("color","x","y"), height=rv$plot_height, width=rv$plot_width) %>%
1281
+ layout(margin=list(b=bot_margin+20))
1282
  }, error=function(e) { showNotification(e$message, type="error"); NULL })
1283
  })
1284
 
 
1629
  output$ammi_plot <- renderPlotly({
1630
  req(stability_analysis())
1631
  tryCatch({
1632
+ ad <- stability_analysis()$ammi_data
1633
+ n_env <- length(unique(ad$Environment))
1634
+ n_gen <- length(unique(ad$Genotype))
1635
+ lbl_angle <- if (n_env > 6) 90 else if (n_env > 3) 45 else 0
1636
+ lbl_hjust <- if (lbl_angle == 90) 1 else if (lbl_angle == 45) 1 else 0.5
1637
+ lbl_vjust <- if (lbl_angle == 90) 0.5 else 1
1638
+ bot_margin <- if (lbl_angle >= 45) 60 else 20
1639
+
1640
  p <- ggplot(ad, aes(x=Environment, y=Mean_Value,
1641
  color=Genotype, group=Genotype)) +
1642
  geom_line(linewidth=1) + geom_point(size=2) +
1643
  labs(title=paste("G×E Interaction —", input$selected_trait),
1644
+ x=NULL, y="Mean Value") +
1645
  theme_minimal() +
1646
+ theme(
1647
+ axis.text.x = element_text(angle=lbl_angle, hjust=lbl_hjust,
1648
+ vjust=lbl_vjust, size=11, color="#000"),
1649
+ axis.text.y = element_text(size=11, color="#000"),
1650
+ axis.title = element_text(size=12, color="#000"),
1651
+ plot.title = element_text(size=13, color="#000", face="bold"),
1652
+ plot.margin = margin(t=10, r=10, b=bot_margin, l=10),
1653
+ legend.position = if (n_gen > 25) "none" else "right",
1654
+ legend.text = element_text(size=8)
1655
+ ) +
1656
+ scale_color_manual(values=get_color_palette(rv$color_scheme, n_gen)) +
1657
+ scale_x_discrete(labels=function(x) stringr::str_wrap(x, width=10))
1658
+
1659
+ ggplotly(p, tooltip=c("color","x","y"), height=rv$plot_height, width=rv$plot_width) %>%
1660
+ layout(margin=list(b=bot_margin+20))
1661
  }, error=function(e) { showNotification(e$message, type="error"); NULL })
1662
  })
1663
 
 
1829
 
1830
  } # end server
1831
 
1832
+ shinyApp(ui=ui, server=server)