본문 바로가기
R

(R) Cleveland dot plot / theme_bw()/adjust elements of x-axis location/hjust/theme()

by jangpiano 2020. 8. 19.
반응형

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

>rownames(USJR)<-NULL

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

>USJR_SUBSET<-USJR[1:3]

>names(USJR_SUBSET)<-c("NAMES","CONTACTS","INTEGRITY")



> USJR_SUBSET_<-USJR_SUBSET[1:20,]


> ggplot(USJR_SUBSET_,aes(x=CONTACTS,y=NAMES))+geom_point()

 > ggplot(USJR_SUBSET_,aes(x=CONTACTS,y=reorder(NAMES,CONTACTS)))

+geom_point()

 

 




> ggplot(data=USJR_SUBSET_,aes(x=CONTACTS,y=reorder(NAMES,CONTACTS)))+geom_point(size=3)


<what theme_bw() does>


ggplot(data=USJR_SUBSET_,aes(x=CONTACTS,y=reorder(NAMES,CONTACTS)))+geom_point(size=3)+theme_bw()

 > ggplot(data=USJR_SUBSET_,aes(x=CONTACTS,y=reorder(NAMES,CONTACTS)))

+geom_point()+theme_grey()

 >

ggplot(data=USJR_SUBSET_,aes(x=CONTACTS,y=reorder(NAMES,CONTACTS)))

+geom_point()+theme_bw()

 

 


>ggplot(data=USJR_SUBSET_,aes(x=CONTACTS,y=reorder(NAMES,CONTACTS)))+geom_point()+theme_bw()+theme(panel.grid.major.x=element_blank())

>ggplot(data=USJR_SUBSET_,aes(x=CONTACTS,y=reorder(NAMES,CONTACTS)))+geom_point()

+theme_bw()

+theme(panel.grid.major.x=element_blank(), panel.grid.minor.x=element_blank())

 >

ggplot(data=USJR_SUBSET_,aes(x=CONTACTS,y=reorder(NAMES,CONTACTS)))+geom_point()

+theme_bw()

+theme(panel.grid.major.x=element_blank(),panel.grid.minor.x=element_blank(),panel.grid.major.y=element_line(linetype="dashed"))

 

 




> ggplot(data=USJR_SUBSET_,aes(x=CONTACTS,y=reorder(NAMES,CONTACTS)))+geom_point()+theme_bw()+theme(panel.grid.major.x=element_blank(),panel.grid.minor.x=element_blank(),panel.grid.major.y=element_line(colour="grey",linetype="dashed"))

<change x-axis and y-axis>

> ggplot(data=USJR_SUBSET_,aes(x=reorder(NAMES,CONTACTS),y=CONTACTS))+geom_point(size=3)+theme_bw()+theme(panel.grid.major.y=element_blank(),panel.grid.minor.y=element_blank(),panel.grid.major.x=element_line(colour="grey",linetype="dashed"))


<what 'hjust' does - adjust the location of elements of x-axis>


>

ggplot(data=USJR_SUBSET_,aes(x=reorder(NAMES,CONTACTS),y=CONTACTS))+geom_point(size=3)

+theme_bw()

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

,panel.grid.minor.y=element_blank()

,panel.grid.major.x=element_line(colour="grey",linetype="dashed")

,axis.text.x=element_text(angle=60))


 >

ggplot(data=USJR_SUBSET_,aes(x=reorder(NAMES,CONTACTS),y=CONTACTS))

+geom_point(size=3)

+theme_bw()

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

,panel.grid.minor.y=element_blank()

,panel.grid.major.x=element_line(colour="grey",linetype="dashed")

,axis.text.x=element_text(angle=60,hjust=1))

 

 


> ggplot(data=USJR_SUBSET_,aes(x=reorder(NAMES,CONTACTS),y=CONTACTS))+geom_point(size=3)+theme_bw()+theme(panel.grid.major.y=element_blank(),panel.grid.minor.y=element_blank(),panel.grid.major.x=element_line(colour="grey",linetype="dashed"),axis.text.x=element_text(angle=60,hjust=0))


> ggplot(data=USJR_SUBSET_,aes(x=reorder(NAMES,CONTACTS),y=CONTACTS))+geom_point(size=3)+theme_bw()+theme(panel.grid.major.y=element_blank(),panel.grid.minor.y=element_blank(),panel.grid.major.x=element_line(colour="grey",linetype="dashed"),axis.text.x=element_text(angle=60,hjust=0.7))

>

ggplot(data=USJR_SUBSET_,aes(x=reorder(NAMES,CONTACTS),y=CONTACTS))+geom_point(size=3)+theme_bw()+theme(panel.grid.major.y=element_blank(),panel.grid.minor.y=element_blank(),panel.grid.major.x=element_line(colour="grey",linetype="dashed"),axis.text.x=element_text(angle=60,hjust=1))




반응형