-1

I am relatively new using the ggplot package. I want to rename the legend of a plot using the names "Sp1" and "Sp2". I have tried to make it using the following code but I have been unable to do it.

This is the code:

t<-read.table ("covartimesfinal2.txt", header=T)

attach(t)

p <- ggplot(t,aes(x=Ratio,y=Time)) + geom_point(aes(shape=factor(Sp)))

p + geom_smooth(aes(linetype=factor(Sp), ),colour="black", method='lm', 

se=F)+theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),panel.background = element_blank(), axis.line = 

element_line(colour = "black"))+

scale_shape_discrete(name  ="Species",labels=c("Sp1", "Sp2"))

My aim is to get rid of the legend named "factor(Sp)" and make the numbers of the axis black and not grey.

Thanks in advance! Please find attached a sample plot

enter image description here

tonytonov
  • 25,060
  • 16
  • 82
  • 98
user12257
  • 11
  • 4
  • 1
    Welcome to SO! Your task looks quite easy, but if you'd like a complete solution, please make a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) by adding a minimal sample of your data. – tonytonov Apr 16 '15 at 10:29
  • 1
    Would it be possible to provide us (part of) covartimesfinal2.txt ? – Ruthger Righart Apr 16 '15 at 11:03
  • Sorry! This is my first post. Is there any way to upload txt files? – user12257 Apr 16 '15 at 18:47

1 Answers1

1

The following drops the unwanted legend labels, I created an own data example:

Data example

t<-data.frame(Ratio=c(1:10,1:10), Time=c(1:10,11:20), Sp=as.factor(c(rep("H", 10), rep("N", 10))))

Ggplot

library(ggplot2)

p <- ggplot(t,aes(x=Ratio,y=Time, group=Sp, shape=Sp)) + geom_point() + geom_line()

p <- p + scale_shape_discrete(name="Species",labels=c("Sp1", "Sp2"))

p <- p + theme(axis.line=element_line(colour = "black"), axis.text=element_text(colour="black"))

enter image description here

Ruthger Righart
  • 4,799
  • 2
  • 28
  • 33