I am trying to create a scatterplot in ggplot2 for R of two variables (two species) differing by color, and within this plot show differences within the two species based on season differing by shape. I ran into this problem when I ran the following code:
Species<- c('1','1','1','1','1','1','1','1','1','1','2','2','2','2','2','2','2','2','2','2')
Age<-c('I','M','M','I','I','M','I','M','I','I','I','M','I','M','M','I','I','I','I','M')
SA<-c(100,90,180,77,65,73,85,87,84,84,82,77,74,65,62,98,120,180,190,100)
V<-c(40,42,45,55,51,62,73,21,41,61,51,92,54,61,65,32,41,55,56,53)
PWstats<-data.frame(Species,Age,SA,V)
PlotSpeciescheck <- ggplot(PWstats,aes(x=log(V), y=log(SA), color=Species, shape=Age)) +
geom_point() +
geom_smooth(method=lm) +
labs(x=expression("Volume ("*cm^3*")"),
y=expression("Surface Area ("*cm^2*")")) +
theme(legend.text = element_text(face="italic"))
It creates multiple lines for each factor (a line for species 1 and season 1, species 2 and season 1, species 2 and season 1, etc.). I only want the lines to represent the two species and have the seasonal differences as a supplemental visualization.
Notice that there are four lines (one for species 1 and age I, species 2 age I, species 1 age M, and species 2 age M), however I only want two lines to show (species 1 and species 2) but still have different shapes representing different age classes.
Is there any way around this? Thank you!