Rstudio Help Boxplot

Hi yall,
I was wondering if anyone could help me figure out how to add Asterisk over specific transcription factors labeled in my x-axis on my boxplot. Each of my TFs has three values and my code is the following. Just as extra info my mutants or my x-axis are my TFs, in this case, TF2 all the way to TF212. I want t highlight about 6 mutants via the asterisk to show their significance.

df <- Normalized_Ranged_Data_of_TF_for_summer_project
new_df <- df %>%
gather(key = "mutant", value = "amount") %>% filter(complete.cases(.))

p <- new_df %>%
ggplot(aes(x=mutant, y=amount)) + geom_boxplot(col=ifelse(colnames(NF)=='TF33',"pink","purple"))

p <- p + theme(axis.text.x = element_text(angle = 90, hjust = 1), text=element_text(size=10,family="Serif")) +
ggtitle("Flocculation Level of Mutants ") +
xlab("Mutant Transcription Factors") + ylab("Degree of Flocculation")

I took the liberty to clean up your code. If you supply some of your data or create a corresponding "dummy"-data, perhaps we can use it as a reference to solve your challenge

# Load libraries ----------------------------------------------------------
library("tidyverse")


# Load data ---------------------------------------------------------------
df <- Normalized_Ranged_Data_of_TF_for_summer_project


# Wrangle data ------------------------------------------------------------
df_long <- df %>%
  pivot_longer(names_to = "mutant", values_to = "amount") %>% 
  mutate(is_TF33 = case_when(mutant == "TF33" ~ TRUE,
                             mutant != "TF33" ~ FALSE)) %>% 
  drop_na


# Visualise ---------------------------------------------------------------
df_long %>%
  ggplot(aes(x = mutant, y = amount, fill = is_TF33)) +
  geom_boxplot() +
  scale_fill_manual(values = c("pink", "purple")) +
  theme(axis.text.x = element_text(angle = 90, hjust = 1),
        text = element_text(size = 10, family = "Serif")) +
  labs(title = "Flocculation Level of Mutants",
       x = "Mutant Transcription Factors",
       y = "Degree of Flocculation")

Thank you so much for your help. I don't know if I can upload my full data but I have a screenshot of some of the data.

Hi @Coolaline13,

Take a look at this then:

# Load libraries ----------------------------------------------------------
library("tidyverse")


# Set example data --------------------------------------------------------
set.seed(9481)
d <- tibble(TF1 = runif(n = 3, min = 0, max = 3),
            TF2 = runif(n = 3, min = 0, max = 3),
            TF3 = runif(n = 3, min = 0, max = 3),
            TF4 = runif(n = 3, min = 0, max = 3))


# Wrangle data ------------------------------------------------------------
d <- d %>%
  pivot_longer(cols = everything(),
               names_to = "mutant",
               values_to = "amount") %>%
  mutate(is_TF3 = case_when(mutant == "TF3" ~ "TF3",
                            TRUE ~ "not_TF3"))


# Visualise ---------------------------------------------------------------
my_plot <- d %>% 
  ggplot(aes(x = is_TF3, y = amount, fill = is_TF3)) +
  geom_boxplot() +
  scale_fill_manual(values = c("pink", "purple")) +
  labs(title = "Flocculation Level of Mutants",
       x = "Mutant Transcription Factors",
       y = "Degree of Flocculation")


# Save visualisation ------------------------------------------------------
ggsave(filename = "Flocculation_Level_of_Mutants.png",
       plot = my_plot, width = 10, height = 6, dpi = 72)

Yielding


Hope it helps :slightly_smiling_face:

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.