Replicating a graph

41 views Asked by At

[enter image description here][1]I have been trying to use GGsignif to allow for brackets to display to bars show a reaction between each other and it keeps saying the mean is not found how would I fix this?

df <- data.frame(
  Raw_data = c(1.0849, 0.3141, 2.4406, 0.645, 1.1113, 0.1619, 2.1256, 0.2496, 1.0502, 0.3083, 2.3525, 0.7906, 1.122, 0.1611, 2.7106, 0.407, 0.8649, 0.1875, 3.0798, 0.711, 0.7667, 0.1841, 2.3361, 0.1597),
  Protein = rep(c("KUF1", "RR16"), each=4),
  Genotype = rep(c("WT", "NSs"), times=4),
  "Rac-GR24" = rep(c("0 μM", "10 μM"), each = 2),
  Protein_genotype = c("KUF1_WT_0", "KUF1_NSs_0", "KUF1_WT_10", "KUF1_NSs_10", "RR16_WT_0", "RR16_NSs_0", "RR16_WT_10", "RR16_NSs_10"),
  Mean =  c(average_KUF1_WT_0UM, average_KUF1_NSs_0UM,average_KUF1_WT_10UM, average_KUF1_NSs_10UM,average_RR16_WT_0UM, average_RR16_NSs_0UM, average_RR16_WT_10UM, average_RR16_NSs_10UM),
  SE = c(SE_KUF1_WT_0UM, SE_KUF1_NSs_0UM, SE_KUF1_WT_10UM, SE_KUF1_NSs_10UM, SE_RR16_WT_0UM, SE_RR16_NSs_0UM,SE_RR16_WT_10UM, SE_RR16_NSs_10UM),
  nudge_amount = c(-0.35,0.185, -0.25, 0.15, -0.3, 0.1, -0.25, 0.25, -0.15, 0.325, -0.25, 0.25, -0.2, 0.4, -0.25, 0.25, -0.25, 0.25, -0.25, 0.35, -0.25, 0.25, -0.25, 0.25)
  )
  
view(df)

df$Genotype <- as.factor(df$Genotype)
df$Genotype <- factor(df$Genotype, levels = c("WT", "NSs"))

Dottedline <- data.frame(Protein=c("KUF1","RR16"),
                         intercept=c(3.5,0))

Realtionship <- list(c("KUF1_WT_0", "KUF1_NSs_0"),
                      c("KUF1_WT_10","KUF1_NSs_10"),
                      c("RR16_WT_0", "RR16_NSs_0"),
                      c("RR16_WT_10", "RR16_NSs_10"))

Realtionship.test <- MutatedData%>%
  t_test(`Relative Expression`~ Protein_Genotype, var.equal = TRUE, comparisons = Realtionship)%>%
  mutate(y.position = c(1.15, 3.1,1.15,3.1))

Realtionship.test$samples <- rep(c("KUF1", "RR16"), each=2)
Realtionship.test$Rac.GR24 <- rep(c("0 μM", "10 μM"), each = 2)
Realtionship.test$Labels <- c("P = 0.0008","P = 0.0012", "P = 0.0021", "P = 0.0003")
Realtionship.test$Mean_NSs <- c(average_KUF1_NSs_0UM,average_KUF1_NSs_10UM,average_RR16_NSs_0UM,average_RR16_NSs_10UM)
Realtionship.test$Mean_WT <- c(average_KUF1_WT_0UM, average_KUF1_WT_10UM, average_RR16_WT_0UM,average_RR16_WT_10UM)

x_axis_margin <- 0.1

Plot <- ggplot(data = df, aes(y = Mean, x = Rac.GR24, fill = Genotype, width = 0.4))+
  geom_bar(stat = "identity", colour="black", width = 1.4, position = position_dodge(width = 0.6))+
  geom_jitter(aes(y = Raw_data, x = Rac.GR24), size = 0.5, fill = NA, pch = 21, stroke = 1.3, position = position_nudge(x=df$nudge_amount)) +
  geom_errorbar(aes(ymax=Mean+SE, ymin=Mean-SE), width=0.4, colour="black", position = position_dodge(0.6))+
  geom_signif(data = df$Genotype, aes(y_position=y.position, xmin = c("KUF1_WT_0","KUF1_WT_10","RR16_WT_0","RR16_WT_10"), xmax = c("KUF1_NSs_0","KUF1_NSs_10","RR16_NSs_0","RR16_NSs_10"), annotations = Labels, manual = TRUE,inherit.aes = FALSE, textsize = 1, size=0.5
))


  [1]: https://i.stack.imgur.com/H1qUm.png
0

There are 0 answers