##Se da lectura al archivo de iris
x<-"C:/Users/aacad/OneDrive/Documents/ADRIANA/FCPYS/R COMO INSTRUMENTO DE INVESTIGACION/a4_iris.csv"
y<-read.csv(x,as.is = TRUE)
str(y)
## 'data.frame': 150 obs. of 5 variables:
## $ sepal.length: num 5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...
## $ sepal.width : num 3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...
## $ petal.length: num 1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ...
## $ petal.width : num 0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ...
## $ variety : chr "Setosa" "Setosa" "Setosa" "Setosa" ...
summary(y)
## sepal.length sepal.width petal.length petal.width
## Min. :4.300 Min. :2.000 Min. :1.000 Min. :0.100
## 1st Qu.:5.100 1st Qu.:2.800 1st Qu.:1.600 1st Qu.:0.300
## Median :5.800 Median :3.000 Median :4.350 Median :1.300
## Mean :5.843 Mean :3.057 Mean :3.758 Mean :1.199
## 3rd Qu.:6.400 3rd Qu.:3.300 3rd Qu.:5.100 3rd Qu.:1.800
## Max. :7.900 Max. :4.400 Max. :6.900 Max. :2.500
## variety
## Length:150
## Class :character
## Mode :character
##
##
##
#Una revisión rápida de los datos muestra que la longitud del sépalo oscila entre 4.3 y 7.9; el ancho de 2 a 4.4; la longitud del pétalo de 1 a 6.9 y el ancho del pétalo de 0.1 a 2.5.
#La pregunta de investigación es si hay diferencia importante en los pétalos de las variedades de flores. Las variables a utilizar son el largo y ancho de pétalos (continuas) y variedades (categórica).
#Se realizará una exploración visual de la relación entre el largo y ancho del pétalo.
library(ggplot2)
petalo<-data.frame(y$petal.length,y$petal.width,y$variety)
names(petalo)<-c("largo","ancho","variedad")
#Gráfico de relación
ggplot(petalo,aes(x=ancho,y=largo,col = variedad))+
geom_point(alpha = 0.3, size=4)+
geom_smooth(method = "lm", se = TRUE, color = "black")
## `geom_smooth()` using formula = 'y ~ x'
#Para mejorar el gráfico se agregaran títulos a los ejes y se hará iteractivo
library(ggplot2)
library(plotly)
## Warning: package 'plotly' was built under R version 4.5.2
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
p<-ggplot(petalo,aes(x=ancho,y=largo,col = variedad))+
geom_point(alpha = 0.3, size=4)+
geom_smooth(method = "lm", se = TRUE, color = "black")+
labs(title = "Relacion entre largo y ancho del petalo ",
x = "Ancho del petalo", y = "Largo del petalo")
ggplotly(p)
## `geom_smooth()` using formula = 'y ~ x'
library(ggplot2)
ggplot(petalo,aes(y=ancho))+
geom_boxplot(alpha = 0.5)+
facet_wrap(~variedad)
#Para mejorar el grafico se agregaran titulos a los ejes, se pondrá color a las cajas.
library(ggplot2)
ggplot(petalo,aes(y=ancho,color=variedad))+
geom_boxplot(alpha = 0.5)+
facet_wrap(~variedad)+
labs(title = "Comparativo de anchos de petalo por variedad",
y = "Ancho del petalo")
library(ggplot2)
ggplot(petalo, aes(x = largo, fill = variedad)) +
geom_histogram(alpha = 0.5, position = "identity", bins = 30)
library(ggplot2)
ggplot(petalo, aes(x = largo, fill = variedad)) +
geom_histogram(alpha = 0.5, position = "identity", bins = 30)+
labs(title = "Comparativo de largos de petalo",
x = "Largo del petalo", y = "Casos")
#Se vuelve a ratificar que la especie Setosa es la de valores más bajos.