0

I am trying to add a legend to my ggplot but I cannot edit the title nor what appears in the legend.

Below is the code that I am using to make the plot;

g <- ggplot()+geom_point(aes(y=Male.SVL,x= number,size=15),
  data=n,show.legend = TRUE)+
  labs(x="Nest", y="SVL (cm)",lab="B")+
  geom_point(aes(y=Female.SVL,x=number,size=15),
  show.legend=TRUE,data=n,color="blue")+
  scale_y_continuous(limits = c(50,200))

g+theme_minimal()+theme(panel.grid.minor=element_blank(),
                      panel.grid.major=element_blank(),
                      axis.line.y = element_line(color = "black"),
                      axis.line.x = element_line(color="black"),
                      axis.text=element_text(size=12,face="bold"),
                      axis.text.x =element_blank(), 
                      axis.title=element_text(size=17),
                      legend.background = element_rect(fill=NULL,size=.5,linetype = 0),
                      legend.position = c(.8,.2),
                      legend.title = element_text(size=12,face="bold"),          
plot.title=element_text(hjust=0.5,size=20,face="bold"))+labs(tag="B")+
scale_color_manual(labels = c("Male","Female"), values = c("black","blue")

Which results in;

R plot

I would like to the legend to say Male="black dot", Female="blue dot"

My dataset looks like this;

ID   Male   Male SVL    Female  Female SVL
3_3_2015    BF-05   180.3   BE-02   124.46
7_7_2013    BF-05   180.3   BE-02   124.46
5_5_2012    CF-79   177.5   BF-33   142.24
CHIM_37_2016    CI-28   194.3   BF-94   133.2

This question is vastly different from other versions because of the integration of two separate geom objects. This detail prevents all other answers provided for manual legend editing from being used and requires a novel and different solution.

Josh
  • 1
  • 1
  • 1
    This is not the `ggplot` way! You should convert data from wide to long, and then use a "gender" variable to map to a `colour` (or `fill`) aesthetic. That will automatically generate a suitable legend for `gender = "Male"` and `gender = "Female"`. Similar questions get asked around here *all the time*. For example take a look at [this post](https://stackoverflow.com/questions/9531904/plot-multiple-columns-on-the-same-graph-in-r) and [this post](https://stackoverflow.com/questions/4877357/how-to-plot-all-the-columns-of-a-data-frame-in-r). – Maurits Evers Aug 09 '18 at 23:45
  • [continued] As this is neither new nor "vastly different", nor requiring "a novel and different solution", nothing is gained from re-opening this question. – Maurits Evers Aug 09 '18 at 23:48

0 Answers0