[R-sig-eco] Change ggplot legend

Luis Fernando García luysgarcia at gmail.com
Thu Apr 16 11:36:59 CEST 2015


Sure!

I can provide a sample graph

I want to get the axis values to be black and remove the legend with the
name "factor(Sp)" and get the values for the axis to be black!

Thanks!


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"))

2015-04-16 6:26 GMT-03:00 Roman Luštrik <roman.lustrik at gmail.com>:

> Can you provide a reproducible example (using some available dataset or
> simulate some data) and perhaps mark on the picture what you want to have
> changed?
>
> Cheers,
> Roman
>
>
> On Thu, Apr 16, 2015 at 11:11 AM, Luis Fernando García <
> luysgarcia at gmail.com> wrote:
>
>> Dear R experts,
>>
>> I am trying to make a new plot. I have already finished and I just want to
>> change the color for the axis number and the legends, I have tried to make
>> the last function by removing the legend and adding a new one but it did
>> not work.
>>
>> If any of you knows how to correct this, I would really appreciate it. My
>> aim is to rename the series as "Sp1" and "Sp2".
>>
>> Thanks in advance!
>>
>> HEre is the plot code
>>
>> 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"))+
>>
>> theme(legend.position="none")+#Remove legend to add a new one
>>
>> scale_shape_discrete(name  ="Species",labels=c("Sp1", "Sp2"))
>>
>>         [[alternative HTML version deleted]]
>>
>> _______________________________________________
>> R-sig-ecology mailing list
>> R-sig-ecology at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
>>
>
>
>
> --
> In God we trust, all others bring data.
>
-------------- next part --------------
Sp	Time	Ratio
H	17	0.85
H	13	0.84
H	7	1.18
H	9	0.90
H	22	2.10
H	12	1.18
H	9	1.10
H	10	0.81
H	11	0.95
H	18	1.75
H	11	1.18
H	24	1.14
H	16	1.27
N	7	2.23
N	9	3.25
N	8	2.92
N	10	4.19
N	10	1.86
N	9	2.03
N	6	1.59
N	4	1.58
N	7	2.44
N	8	1.46
N	8	2.21
N	8	1.48
N	15	1.5
N	15	2.1
N	8	1.58
N	10	2.03
N	12	1.92
N	7	1.49
N	12	2.1
N	7	2.45
N	7	1.74
N	6	1.81
N	9	1.7
N	11	1.47
N	10	1.85
N	6	2.29


More information about the R-sig-ecology mailing list