0

enter image description hereI'm reading in a csv file and using ggplot to make a box plot and having issues with the size of the text on the x axis. I can't reduce the text size because I am reducing the over all image for a manuscript and this is the optimal size to make the axes visible. I'd like to have the genotype names below each box plot on the x axis, I've angled genotype names on the axis, but it still doesn't seem to be enough and looks a bit awkward. I'd like to add a line break for at least the longest genotype (4-67/Chrimson), but I don't think I am doing this right. I've tried setting new labels using in the scale_x_discrete and also in the axis.text.x but under both conditions, it either skips over that variable or ignores the command.

FYI: the data frame has two variables, group activity and genotype and genotype has 4 levels.

Thank you in advance!!

Here's my code so far..

dat5=read.csv("Time Point 120 Raw Data C-Test.csv") 

plot5<- ggplot(dat5, aes(x = Genotype, y = Group.Activity, col = Genotype, fill = Genotype, ymin= -40, ymax = 50)) +
      geom_boxplot(fatten = 1, lwd = .5, alpha = .6) +
      # reorder so x-axis is not alphabetical 
      scale_x_discrete(limits=c("4-67/Chrimson","4-67/+","+/Chrimson", "+/+"))+
      scale_fill_manual(values=c("#F99205", "#4ED55F", "#36A6D6", "#5752D0"))+
      scale_color_manual(values=c("#F99205", "#4ED55F", "#36A6D6", "#5752D0"))+
      geom_beeswarm(size = 1.5, alpha = .75, cex = 3)+
      ylab("Percent Activity After Baseline Subtraction")+
      theme_classic()+
      theme(axis.title.x = element_blank(), axis.text.x = element_text(size = 16, color="black"), axis.ticks.x = element_blank())+
      theme(axis.text.y = element_text(size = 24, color="black"), axis.ticks.y = element_blank())+
      theme(axis.title.y = element_text (size = 24, color="black"))+
      theme(axis.ticks.x = element_blank())+
      theme(legend.position = "none")
Kristin
  • 13
  • 5
  • 2
    Any data or example image? It's is very difficult to figure out what do you want just with the code. – S Rivero Jul 03 '17 at 14:25
  • 1
    Did you google for it? Check the second hit for instance: https://stackoverflow.com/questions/20123147/add-line-break-to-axis-labels-and-ticks-in-ggplot – Roman Jul 03 '17 at 14:27
  • I've been googling for a while, and found several iterations for substituting spaces with line breaks, but none seem to work with my code in scale_x_discrete. I think it's because I am reorganizing the order of my variables with scale_x_discrete limits. I've tried using #levels(dat1Test$Genotype) <- gsub(" ", "\n", levels(dat1Test$Genotype)) and my.labels <- c("2-72/\nChrimson","2-72/+","+/\nChrimson", "+/+") scale_x_discrete(limits=c("2-72/Chrimson","2-72/+","+/Chrimson", "+/+", labels=my.labels))+ and neither seem to work. They just make a graph without the genotypes. – Kristin Jul 03 '17 at 20:39
  • S Rivero- I've included an image for your reference... – Kristin Jul 03 '17 at 21:00
  • Nevermind!! I reorganized my variables in the csv file instead of scale_x_discrete. I was then able to add line breaks – Kristin Jul 03 '17 at 23:07

0 Answers0