2

I am using this data https://www.dropbox.com/s/aqt7bdhzlwdsxl2/summary_exp1.csv

And the following code:

pd <- position_dodge(.1)
ggplot(data=summary.200.exp1, aes(x=Time, y=Length, colour=Genotype, group=Genotype)) + 
    geom_errorbar(aes(ymin=Length - se, ymax=Length + se), colour="black", width=.1,         position=pd) +
  geom_line(position=pd) +
  geom_point(aes(shape=Genotype),position=pd, size=3) +
  ylab("leaf segment width (mm)") +
  xlab("Time") +
   theme(axis.title = element_text(size=14,face="bold"), 
        axis.text = element_text(size=14),
        strip.text.y = element_text(size=14))

I need to make the following modifications:

  1. Adjust the x-axis limits to eliminate the spaces between the y-axis and the data plotted at time0 and then between Time22 and the edge of the graph. I have looked at documentation and tried this: scale_x_discrete(limits=c("0","22")), but it doesn't work.
  2. Modify labelling so that each line on the graph is labelled with a distinct colour, the "Genotype" and the legend is eliminated. For this I have tried various options with geom_text(aes(colour=Genotype)), which I also cannot get to work.

I would appreciate any help with this. Many thanks

1 Answer 1

1
  1. You can eliminate the space between the plot and the axis by adding expand = c(0, 0) to the scale parameter:scale_x_discrete(expand = c(0, 0))
  2. You can eliminate the legend by adding show_guide=FALSE to e.g. the geom_line part of your code.

EDIT:

I think your are trying to plot to much into one graph. The errorbars, for example, overlap each other to much to get a readable plot. Using facets might be a good idea in this case (in my opinion). the following code (in which named the dataframe as dat):

ggplot(data=dat, aes(x=Time, y=Length, colour=Genotype)) + 
  geom_line() +
  geom_point(aes(shape=Genotype), size=3) +
  scale_shape_manual(values=c(19,17,15,8,13,6,12,4)) +
  geom_errorbar(aes(ymin=Length-se, ymax=Length+se, colour=Genotype), width=.2) +
  guides(colour=FALSE, shape=FALSE) +
  facet_wrap(~Genotype, ncol=4)

results in this plot: enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Jaap, much appreciated. Do you have any help with how to get the labelling (I am assuming geom_text is needed, but the graph disappears when I use the code I explained above in #2). Also, when I use show_guide = FALSE as you suggested, I get two genotype symbols disappearing (CD and RIL4), but the text remains in the legend and the other symbols remain in the legend.
The reason for the disappearing symbols is that the shape scale can only deal with 6 discrete values. If you have more, you need to specify them manually. Moreover I think it is wise in your case to use facets. See my updated answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.