Jame H
Jame H

Reputation: 1384

How to change legend in shape of ggplot

I have a trouble about the legend of shape in R.

I used ggplot to draw a graph like this:

ggplot(data,aes(x=ex1score,y=ex2score,shape=m_shape,color=m_shape))+  
  geom_point()

enter image description here

But I want to change:

m_shape --> result

0--> fail

1-->pass

Please help me to solve this problem.

Thank a lot

Upvotes: 1

Views: 4093

Answers (1)

Haboryme
Haboryme

Reputation: 4761

You could do:

ggplot(data,aes(x=ex1score,y=ex2score,shape=m_shape,color=m_shape))+
  geom_point()+
  scale_color_discrete(labels=c("fail","pass"),name="result")+
  scale_shape_discrete(labels=c("fail","pass"),name="result")

I don't think you can get away with only specifying the labels and name once since m_shape affects both shape and color

Upvotes: 4

Related Questions