# Đổi theme mặc định old_theme<-theme_update( plot.background=element_rect(fill="#3366FF"), panel.background=element_rect(fill="#003DF5"), axis.text.x=element_text(colour="#CCFF33"), axis.text.y=element_text(colour="#CCFF33",hjust=1), axis.title.x=element_text(colour="#CCFF33",face="bold"), axis.title.y=element_text(colour="#CCFF33",face="bold", angle=90) ) # Kết quả đổi theme qplot(cut,data=diamonds,geom="bar")
qplot(cty,hwy,data=mpg)
## Error: ggplot2 doesn't know how to deal with data of class numeric
# Đặt lại theme theme_set(old_theme) # Kết quả đặt lại qplot(cut,data=diamonds,geom="bar")
qplot(cty,hwy,data=mpg)
## Error: ggplot2 doesn't know how to deal with data of class numeric
Tùy chỉnh scales và geoms
scale
# Thay đổi scale mặc định bằng cách gán hàm scale_colour_discrete<-scale_colour_grey scale_fill_discrete<-scale_fill_grey scale_colour_continuous<-function(...) scale_colour_gradient(low="white",high="black") scale_fill_continuos<-function(...) scale_fill_gradient(low="white",high="black")
# A viewport that takes up the entire plot device library(grid) vp1<-viewport(width=1,height=1,x=0.5,y=0.5) vp1<-viewport()
# A viewport that takes up half the width and half the height, # located in the middle of the plot. vp2<-viewport(width=0.5,height=0.5,x=0.5,y=0.5) vp2<-viewport(width=0.5,height=0.5)
# A viewport that is 2cm x 3cm located in the center vp3<-viewport(width=unit(2,"cm"),height=unit(3,"cm"))
# A viewport in the top right vp4<-viewport(x=1,y=1,just=c("right","top")) # Bottom left vp5<-viewport(x=0,y=0,just=c("right","bottom"))
Biểu đồ con
pdf("polishing-subplot-1.pdf",width=4,height=4) subvp<-viewport(width=0.4,height=0.4,x=0.75,y=0.35) b print(c,vp=subvp) dev.off()
# Sửa cho đẹp csmall<-c+ theme_gray(9)+ labs(x=NULL,y=NULL)+ theme(plot.margin=unit(rep(0,4),"lines"))
pdf("polishing-subplot-2.pdf",width=4,height=4) b print(csmall,vp=subvp) dev.off()