user2978586
user2978586

Reputation:

ggplot2 graph x axis and line labels

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

Upvotes: 2

Views: 478

Answers (1)

Jaap
Jaap

Reputation: 83215

  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

Upvotes: 1

Related Questions