본문 바로가기
R

(R) scatter dot plot/ distinguish by discrete colour/by shape/ by colour and shape/ by filling and vacant

by jangpiano 2020. 8. 25.
반응형

> ?USJudgeRatings

> mean(USJudgeRatings$PREP)

[1] 7.467442


> mean(USJudgeRatings$INTG)

[1] 8.02093


> USJudgeRatings_<-USJudgeRatings%>%mutate(INTGR=ifelse(INTG>8.02,"HIGH","LOW"),PREPR=ifelse(PREP>7.46,"LONG","SHORT"))


<scatter dot plot - geom_point()>

> ggplot(data=USJudgeRatings,aes(x=DILG,y=FAMI))+geom_point()

> ggplot(data=USJudgeRatings,aes(x=DILG,y=FAMI))+geom_point(shape=3)

<shape types in R>



<distinguish by color or shape>

> ggplot(data=USJudgeRatings_,aes(x=DILG,y=FAMI,colour=PREPR))+geom_point()

> ggplot(data=USJudgeRatings_,aes(x=DILG,y=FAMI,colour=PREPR))

   +geom_point(size=2.5)


 *original size set is 2. 

 > ggplot(data=USJudgeRatings_,aes(x=DILG,y=FAMI,shape=PREPR))

+geom_point(size=2.5)

 

 



> ggplot(data=USJudgeRatings_,aes(x=DILG,y=FAMI,shape=PREPR))+geom_point(size=3)+scale_shape_manual(values=c(1,4))

<distinguish by color & shape>

> ggplot(data=USJudgeRatings_,aes(x=DILG,  y=FAMI,  shape=PREPR,  colour=INTGR)) + geom_point()


> ggplot(data=USJudgeRatings_,aes(x=DILG,y=FAMI,shape=PREPR,colour=INTGR))+geom_point()+scale_colour_brewer(palette="Set1")


> ggplot(data=USJudgeRatings_,aes(x=DILG,y=FAMI,shape=PREPR,colour=INTGR))+geom_point()+scale_colour_brewer(palette="Set1")+scale_shape_manual(values=c(1,2))


<distinguish by being filled or vacant>


If you want to make a graph with both filled and vacant points, you should set shapes of the points with over 20. This is because shapes having number over 20 is able to be set colour and fill separately. However, shapes under 20 should have the same shape and colour.


so First, you should set shapes of points over 20 -----------------scale_shape_manual(values=c(21,24))

Next, you should distinguish points by setting a filling colour of points as NA. ----------------scale_fill_manual(values=c(NA,"red"))


> ggplot(data=USJudgeRatings_,aes(x=DILG,y=FAMI,shape=PREPR,fill=INTGR))+geom_point(size=3)+scale_fill_manual(values=c(NA,"red"))+scale_shape_manual(values=c(21,24))


반응형