LearningAlgorithm
LearningAlgorithm

Reputation: 247

Problems with x label when using labs (ggplot)

I was doing a plot with ggplot in R with this code:

order <- c('Pfu gamma 0min replicate1','Pfu gamma 20min replicate1','Pfu gamma 40min replicate1','Pfu gamma 60min replicate1','Pfu gamma 120min replicate1','Pfu reference replicate1')
ggplot(data=Genome1,aes(x=factor(Sample,level=order), y=mRNA, fill=Sample)) +
  geom_boxplot() +
  scale_x_discrete(labels=c("Pfu gamma 0min replicate1"="0min","Pfu gamma 20min replicate1"="20min","Pfu gamma 40min replicate1"="40min","Pfu gamma 60min replicate1"="60min","Pfu gamma 120min replicate1"="120min","Pfu reference replicate1"="REF")) +
  stat_boxplot(geom = "errorbar") +
  labs(title="mRNA vs Time", subtitle="Genome",xlab="Sample",y="mRNA")+
  theme(plot.title = element_text(hjust = 0.5),plot.subtitle = element_text(hjust = 0.5))

The problem is that it shows as xlabel "factor(Sample,level=order)". Is it due to the fact that I used factor in aes? It should show "Sample".

I have an additional question: I was trying to do a plot with a dataframe that has 3 columns and about 55000 rows but my computer seems not to support it. Is R not able to do support such size ?

Upvotes: 0

Views: 355

Answers (1)

rodolfoksveiga
rodolfoksveiga

Reputation: 1261

Wellcome to Stack Overflow Manuela. Your problem is simple, nothing to worry about... You can solve changing the argument xlab to x, inside labs().

ggplot(data = Genome1,
       aes(x = factor(Sample, level = order), y = mRNA, fill = Sample)) +
   geom_boxplot() +
   scale_x_discrete(labels=c("Pfu gamma 0min replicate1" = "0min",
                             "Pfu gamma 20min replicate1" = "20min",
                             "Pfu gamma 40min replicate1" = "40min",
                             "Pfu gamma 60min replicate1" = "60min",
                             "Pfu gamma 120min replicate1" = "120min",
                             "Pfu reference replicate1" = "REF")) +
   stat_boxplot(geom = "errorbar") +
   labs(title = "mRNA vs Time",
        subtitle = "Genome",
        x = "Sample",
        y = "mRNA")+
   theme(plot.title = element_text(hjust = 0.5),
         plot.subtitle = element_text(hjust = 0.5))

Upvotes: 1

Related Questions