본문 바로가기
R

(R)Cleveland dot graph - three variables (by coloring by elements of a variable)

by jangpiano 2020. 8. 19.
반응형

> USJR<-cbind(rownames(USJudgeRatings),USJudgeRatings)

> rownames(USJR)<-NULL

> colnames(USJR)[1]<-"NAME"

> mean(USJR$INTG)  ------------INTG : Judical Integrity of lawyers.

[1] 8.02093


> USJR<-USJR%>%mutate(rank_INTG=ifelse(INTG<=8.02093,"HIGH","LOW"))


> table(USJR$rank_INTG)

HIGH  LOW 

  19   24


> View(USJR)


> USJR_<-USJR%>%select(NAME,CONT,rank_INTG)

> View(USJR_)


> USJR_<-USJR_[1:20,]



<geom_segment()>

> ggplot(data=USJR_,aes(x=CONT,y=NAME))

+geom_point()+theme_bw()+theme(panel.grid.major.y=element_blank())

 > ggplot(data=USJR_,aes(x=CONT,y=NAME))

+geom_segment(aes(yend=NAME),xend=0)

+geom_point()+theme_bw()+theme(panel.grid.major.y=element_blank())

 

 


<geom_point(aes(colour=))>


> ggplot(data=USJR_,aes(x=CONT,y=NAME))+geom_segment(aes(yend=NAME),xend=0,colour="grey")+geom_point(size=3,aes(colour=rank_INTG))+theme_bw()+theme(panel.grid.major.y=element_blank())

> ggplot(data=USJR_,aes(x=CONT,y=NAME))+geom_segment(aes(yend=NAME),xend=0,colour="grey")+geom_point(size=3,aes(colour=rank_INTG))+scale_colour_brewer(palette="Set1",limits=c("HIGH","LOW"))+theme_bw()+theme(panel.grid.major.y=element_blank())

> ggplot(data=USJR_,aes(x=CONT,y=NAME))+geom_segment(aes(yend=NAME),xend=0,colour="grey")+geom_point(size=3,aes(colour=rank_INTG))+scale_colour_manual(values=c("blue","red"),limits=c("HIGH","LOW"))+theme_bw()+theme(panel.grid.major.y=element_blank())

> ggplot(data=USJR_,aes(x=CONT,y=reorder(NAME,CONT)))+geom_segment(aes(yend=NAME),xend=0,colour="grey")+geom_point(size=3,aes(colour=rank_INTG))+scale_colour_manual(values=c("blue","red"),limits=c("HIGH","LOW"))+theme_bw()+theme(panel.grid.major.y=element_blank())

> ggplot(data=USJR_,aes(x=CONT,y=reorder(NAME,CONT)))+geom_segment(aes(yend=NAME),xend=0,colour="grey")+geom_point(size=3,aes(colour=rank_INTG))+scale_colour_manual(values=c("blue","red"),limits=c("HIGH","LOW"))+theme_bw()+theme(panel.grid.major.y=element_blank())+facet_grid(rank_INTG ~.)


> ggplot(data=USJR_,aes(x=CONT,y=reorder(NAME,CONT)))+geom_segment(aes(yend=NAME),xend=0,colour="grey")+geom_point(size=3,aes(colour=rank_INTG))+scale_colour_manual(values=c("blue","red"),limits=c("HIGH","LOW"))+theme_bw()+theme(panel.grid.major.y=element_blank())+facet_grid(rank_INTG ~.,scales="free_y")


> ggplot(data=USJR_,aes(x=CONT,y=reorder(NAME,CONT)))+geom_segment(aes(yend=NAME),xend=0,colour="grey")+geom_point(size=3,aes(colour=rank_INTG))+scale_colour_manual(values=c("blue","red"),limits=c("HIGH","LOW"),guide=FALSE)+theme_bw()+theme(panel.grid.major.y=element_blank())+facet_grid(rank_INTG ~.,scales="free_y",space="free_y")

CL





반응형