본문 바로가기
R

(R) divide graph in two parts based on x-axis, exclude guide from bar graph

by jangpiano 2020. 8. 14.
반응형
<Divide graph into two parts based on x-axis>



> msleep<-msleep%>%filter(!is.na(sleep_rem))
> mean(msleep$sleep_rem)
[1] 1.87541

> msleep<-msleep%>%mutate(sleep_rem_d=sleep_rem-1.87541)
> msleep2<-msleep%>%mutate(rem_rank=ifelse(sleep_rem_d<=0,"little","much"))%>%group_by(vore,rem_rank)
> ggplot(data=msleep2,aes(x=vore,y=sleep_rem_d,fill=rem_rank))+geom_bar(stat="identity")


> ggplot(data=msleep2,aes(x=vore,y=sleep_rem_d,fill=rem_rank))+geom_bar(position="dodge",stat="identity")

> ggplot(data=msleep2,aes(x=vore,y=sleep_rem_d,fill=rem_rank))+geom_bar(position="dodge",stat="identity")+scale_fill_brewer(palette=10)

> ggplot(data=msleep2,aes(x=vore,y=sleep_rem_d,fill=rem_rank))+geom_bar(position="dodge",stat="identity")+scale_fill_manual(values=c("blue1","lightblue"))


<Exclude the guide in the right side - guide=False>

> ggplot(data=msleep2,aes(x=vore,y=sleep_rem_d,fill=rem_rank))+geom_bar(position="dodge",stat="identity")+scale_fill_manual(values=c("blue1","lightblue"),guide=FALSE)

<has a guide in the right side> 


> ggplot(data=msleep2,aes(x=vore,y=sleep_rem_d,fill=rem_rank))

+geom_bar(position="dodge",stat="identity")

+scale_fill_manual(values=c("blue1","lightblue"))

 

<delete the guide in the right side> 


> ggplot(data=msleep2,aes(x=vore,y=sleep_rem_d,fill=rem_rank))

+geom_bar(position="dodge",stat="identity")

+scale_fill_manual(values=c("blue1","lightblue"),guide=FALSE)


 

 









반응형