# Dùng last_plot() để phóng to đoạn quan tâm qplot(x,y,data=diamonds,na.rm=TRUE)
last_plot()+xlim(3,11)+ylim(3,11)
last_plot()+xlim(4,10)+ylim(4,10)
## Scale for 'x' is already present. Adding another scale for 'x', which will replace the existing scale. ## Scale for 'y' is already present. Adding another scale for 'y', which will replace the existing scale.
last_plot()+xlim(4,5)+ylim(4,5)
## Scale for 'x' is already present. Adding another scale for 'x', which will replace the existing scale. ## Scale for 'y' is already present. Adding another scale for 'y', which will replace the existing scale.
last_plot()+xlim(4,4.5)+ylim(4,4.5)
## Scale for 'x' is already present. Adding another scale for 'x', which will replace the existing scale. ## Scale for 'y' is already present. Adding another scale for 'y', which will replace the existing scale.
last_plot()+geom_abline(colour="red")
# Lệnh tổng hợp cuối cùng qplot(x,y,data=diamonds,na.rm=T)+ geom_abline(colour="red")+ xlim(4,4.5)+ylim(4,4.5)
pcp_data<-function(df){ libs<-c("plyr","reshape2") lapply(libs,require,character.only=TRUE) numeric<-laply(df,is.numeric) # Rescale numeric columns range01<-function(x)x/range(x) df[numeric]<-colwise(range01)(df[numeric]) # Add row identified df$.row<-rownames(df) # Melt, using non-numeric variables as id vars dfm<-melt(df,id=c(".row",names(df)[!numeric])) # Add pcp to class of the data frame class(dfm)<-c("pcp",class(dfm)) dfm } pcp<-function(df,...){ df<-pcp_data(df) ggplot(df,aes(variable,value))+geom_line(aes(group=.row)) } pcp(mpg)