exploratory_plot = function(x,y){ # testando premissas if (!(is.numeric(x) & is.numeric(y))){ stop("Objetos devem ser numéricos.") } else{ if(length(x)!=length(y)){ stop("Objetos devem ter o mesmo tamanho.") } } #paleta de cores clrs = topo.colors(2, alpha = 0.6) #lm lm.xy = lm(y~x) # calculo limite eixo para histograma xmin = min(c(range(x), range(y))) xmax = max(c(range(x), range(y))) ymax = max(c(hist(x,plot = FALSE)$counts, hist(y,plot = FALSE)$counts)) + 10 # plots par(mfrow=c(3,2), pch = 19, mar = c(4,4.5,2,2)) #boxplot boxplot(x,y, col = clrs, outline = T, names = c("x","y")) #histograma hist(x, col = clrs[1], xlim = c(xmin,xmax), ylim = c(0,ymax), main =" ", xlab = " ", ylab = "Frequência") hist(y, col = clrs[2], xlim = c(xmin,xmax), ylim = c(0,ymax), add = T, main = " ") legend("topright", c("x", "y"),bty="n", fill=clrs, pt.cex=0.2) # plor x~y plot(y~x) abline(lm.xy, col = "firebrick") # qqplot x qqnorm(x, col = clrs[1], xlab = "Quantis Teóricos", ylab = "Quantis da Amostra", main = "Normal QQ Plot de 'x'") qqline(x, lwd = 1.3, col="firebrick") #qqplot y qqnorm(y, col = clrs[2], xlab = "Quantis Teóricos", ylab = "Quantis da Amostra", main = "Normal QQ Plot de 'y'") qqline(y, lwd = 1.3, col="firebrick") par(mfrow=c(1,1)) #retorna sumario das variaveis e coeficiente da regressao ret = list(summary(x), summary(y), lm.xy$coefficients) names(ret) <- c("x", "y", "coefficients") return(ret) } # testes x = rnorm(200,20,5) y = rnorm(200,2,10) exploratory_plot(x,y) exploratory_plot(iris$Sepal.Length, iris$Sepal.Width) exploratory_plot(cars$speed, cars$dist) # Os graficos ficariam mais bonitos se os breaks dos dois histogramas tivessem o mesmo taamnho. # Tentei sincronizar de algumas maneiras mas não tive sucesso.