csv$Date <- as.Date(csv$date)
plot(csv$Date, csv$AMZN, type='l', col='blue',
xlab='Fechas', ylab='Adjusted Price', main='Gráfico de líneas - Amazon')
Para el primer grafico tenemos la visualizacion del comportamiento del precio ajustado de AMAZON.
visualizar_precios <- function(datos) {
plot_ly(datos, x = ~as.Date(date)) %>%
add_lines(y = ~AAPL, name = "APPLE") %>%
add_lines(y = ~GOOG, name = "GOOGLE") %>%
add_lines(y = ~AMZN, name = "AMAZON") %>%
add_lines(y = ~FB, name = "FACEBOOK") %>%
add_lines(y = ~NFLX, name = "NETFLIX") %>%
add_lines(y = ~MSFT, name = "MICROSOFT") %>%
layout(title = "Precios", xaxis = list(title = "Date"), yaxis = list(title = "Price"))
}
# Llamar a la función con tus datos
visualizar_precios(csv)
Para el tercer grafico comparamos en un mismo plot la evolucion los precios de distintos stocks: Google, Apple, Amazon, Facebook, netflix y Microsoft. Logramos ver como el precio de netflix lideraba la agrupacion, hasta julio de 2019. Finalmente, Microsoft toma mayor peso en la grafica.
USA<- read.csv("https://raw.githubusercontent.com/lorenzog-ryzen/tasks_data_viz/main/df_us.csv")
barplot(round(USA$pop), names.arg = USA$year,col="#5BA2CC", xlab = "Año", ylab = "Población", main = "Poblacion")
Para el cuarto grafico se muestra la poblacion de estados unidos, creciendo con el tiempo. Donde comienza con menos de 50 millones, y termina en mas de 150 millones.
df_tips<-read.csv("https://raw.githubusercontent.com/lorenzog-ryzen/tasks_data_viz/main/df_tips.csv")
ggplot(df_tips, aes(x = day, y = tip, fill = sex)) +
geom_bar(stat = "identity", position = "stack") +
labs(x = "Day of the Week", y = "Tip Amount", title = "Tips by Sex on Each Day")
Para el quinto grafico agrupamos los sexos, uno encima de otro para los dias: Viernes, sabado, domingo y martes. Agrupandolos asi podemos tener en cuenta el total de estos y su proporcion. Vemos que sabado y domingo son los dias con mayor cantidad y los hombres ocopuan la mayor parte de los datos en estos dias.
ggplot(df_tips, aes(x = sex, y = total_bill, fill = smoker)) +
geom_bar(stat = "identity", position = "dodge") +
labs(x = "Day of the Week", y = "total_bill", title = "Tips by Sex on Each Day")
Para el sexto grafico tenemos la muestra distribuida por sexo y si fuman o no, en realcion a cuato reciben. Se aprecia como los hombres reciben mas que las mujeres, sin importar si fuman o no. Ademas, en ambos sexos las personas que si fuman reciben mas.
df_asia<-read.csv("https://raw.githubusercontent.com/lorenzog-ryzen/tasks_data_viz/main/df_asia.csv")
barplot(round(df_asia$pop), names.arg = df_asia$country,col="#5BA2CC", xlab = "Pais", ylab = "Population in Asia", main = "Población Por pais en Asia")
Para el septimo grafico Tenemos la poblacion de Asia distribuida por pais. Gracias a este grafico de barras vemos como China es el pais con maoyr poblacion e india el segundo, pero es de apreciar que sobrepasan por mucho la poblacion del resto de los paises de Asia.
Iris<-read.csv("https://raw.githubusercontent.com/lorenzog-ryzen/tasks_data_viz/main/Iris.csv")
ggplot(Iris, aes(x = SepalWidthCm, y = SepalLengthCm, color = Species, size = PetalLengthCm)) +
geom_point() +
labs(x = "Sepal Width (cm)", y = "Sepal Length (cm)", size = "Petal Length (cm)", color = "Species") +
theme_minimal()
Para el Octavo grafico comparamos el ancho del sepalo, con el largo de este, diferenciando a cada individuo por el largo del petalo y agrupandolos por especiaes. Vemos que los iris_setosa tienen el menor largo del petalo. Ademas, estos tambien poseen el menor largo del sepalo en comparacion con el ancho.
ggplot(Iris, aes(x = SepalWidthCm, y = SepalLengthCm, color = SepalWidthCm)) +
geom_point() +
labs(x = "Sepal Width (cm)", y = "Sepal Length (cm)", size = "Petal Length (cm)", color = "") +
theme_minimal() +
scale_color_gradient(low = "orange", high = "blue")
Para el noveno grafico tenemos algo parecido al grafico anterior, pero ahora comparamos el ancho del sepalo y el largo de este, sin tener en cuenta la especie. Ademas, se clasifica el color de cada individuo en base al ancho del sepalo.
set.seed(123) # Para reproducibilidad
x <- rnorm(100000)
y <- rnorm(100000)
color <- rnorm(100000)
# Crear el gráfico de dispersión
fig <- plot_ly(x = ~x, y = ~y, mode = "markers", marker = list(color = ~color, colorscale = "Viridis", line = list(width = 1)))
fig
## No trace type specified:
## Based on info supplied, a 'scatter' trace seems appropriate.
## Read more about this trace type -> https://plotly.com/r/reference/#scatter
Para el decimo grafico generamos 100000 datos aleatorios y los contrastamos entre si, ademas los clasificamos por una escala aleatoria de 10000 colores.
df_samer<-read.csv("https://raw.githubusercontent.com/lorenzog-ryzen/tasks_data_viz/main/df_samer.csv")
plot_ly(labels=df_samer$country, values=df_samer$pop, type="pie")
Para el grafico 11 Tenemos un grafico de pastel el valor la poblacion de los paises de asia. Volvemos a ver como la mayor parte de la torta la componen china e india.
colors = c('blue', 'green', 'black', 'purple', 'red', 'brown')
plot_ly(labels=c('Water','Grass','Normal','Psychic', 'Fire', 'Ground')
, values=c(110,90,80,80,70,60), type="pie") %>%
layout(
hoverinfo = "label+percent",
textfont = list(size = 20),
textinfo = "label+percent",
pull = c(0.1, 0, 0.2, 0, 0),
marker = list(colors = colors, line = list(color = "#FFFFFF", width = 2))
)
## Warning: 'layout' objects don't have these attributes: 'hoverinfo', 'textfont', 'textinfo', 'pull', 'marker'
## Valid attributes include:
## '_deprecated', 'activeshape', 'annotations', 'autosize', 'autotypenumbers', 'calendar', 'clickmode', 'coloraxis', 'colorscale', 'colorway', 'computed', 'datarevision', 'dragmode', 'editrevision', 'editType', 'font', 'geo', 'grid', 'height', 'hidesources', 'hoverdistance', 'hoverlabel', 'hovermode', 'images', 'legend', 'mapbox', 'margin', 'meta', 'metasrc', 'modebar', 'newshape', 'paper_bgcolor', 'plot_bgcolor', 'polar', 'scene', 'selectdirection', 'selectionrevision', 'separators', 'shapes', 'showlegend', 'sliders', 'smith', 'spikedistance', 'template', 'ternary', 'title', 'transition', 'uirevision', 'uniformtext', 'updatemenus', 'width', 'xaxis', 'yaxis', 'barmode', 'bargap', 'mapType'
Para el grafico 12 tenemos otro pastel para unos datos seleccionados manualmente. Vemos que casi todas las variables tienen el mismo porcentaje en el pastel. Pero el Agua posee el mayor porcentaje, con 22.4% y el fuego posee la menor parte con un 14.3% .
set.seed(123) # Para reproducibilidad
dice_1 <- sample(1:6, 5000, replace = TRUE)
dice_2 <- sample(1:6, 5000, replace = TRUE)
dice_sum <- dice_1 + dice_2
# Crear el histograma
histogram <- plot_ly(x = ~dice_sum, type = "histogram", nbinsx = 11) %>%
layout(
xaxis = list(title = "Dice Roll"),
yaxis = list(title = "Frequency"),
title = "5000 Dice Roll Histogram",
bargap = 0.2,
showlegend = FALSE
)
# Crear el gráfico de violín
violin <- plot_ly(x = rep("Dice Roll", length(dice_sum)), y = ~dice_sum, type = "violin", box = list(visible = FALSE)) %>%
layout(
xaxis = list(title = ""),
yaxis = list(title = "Dice Roll"),
showlegend = FALSE
)
# Combinar histograma y gráfico de violín
subplot <- subplot( violin,histogram, nrows = 2, heights = c( 0.15,0.75))
# Mostrar el gráfico
subplot
Para el grafico 13 se declaran dos variables con datos aleatorios. Luego representamos los datos bajo un histograma y anexamos un grafico de violin en la parte superior. En donde el grafico de violin representa algo como la informacion que proporciona un boxplot.
plot_ly(data = df_tips, x = ~total_bill, type = "histogram", color = ~sex) %>%
layout(
xaxis = list(title = "Total Bill"),
yaxis = list(title = "Count"),
title = "Histogram of Total Bill by Sex"
)
## Warning in RColorBrewer::brewer.pal(N, "Set2"): minimal value for n is 3, returning requested palette with 3 different levels
## Warning in RColorBrewer::brewer.pal(N, "Set2"): minimal value for n is 3, returning requested palette with 3 different levels
Para el grafico 14 tenemos el histograma de la distribucion de el total de billetes en relacion a la cantidad, diferenciando los colores por sexo. Aqui tambien logramos apreciar que a todos los valores totales de billetes hay una mayor cantidad en los hombres.
plot_ly(data = df_tips, x = ~sex, y = ~tip, type = "box", boxpoints = "all") %>%
layout(
xaxis = list(title = "Sex"),
yaxis = list(title = "Tip"),
title = "Boxplot of Tip by Sex"
)
El grafico 15 es de caja y bigotes entre hombres y mujeres en realcion a la propina. vemos que entre los dos sexos existe una varianza similar con una mediana parecida, al igual que los bigotes. Ahora cuando vemos la grafica de dispersion de cada individuo, donde si hay una mayor diferencia, ya que los hombres llegan a tomar mayores propinas que las mujeres.
plot_ly(data = df_tips, x = ~day, y = ~tip, type = "box") %>%
layout(
xaxis = list(title = "day"),
yaxis = list(title = "Tip"),
title = "Boxplot of Tip by Sex"
)
El grafico 16 tenemos un grafico de cajas para cada dia. Aqui podemos apreciar que por dia los sexos toman varianzas distintas. El dia mas destacado es el sabado, donde hay datos atipicos y los hombres alcanzan un mayor valor que el de las mujeres.
plot_ly(data = df_tips, x = ~sex, y = ~tip, type = "box",
boxmean = TRUE, marker = list(color = "blue")) %>%
layout(
xaxis = list(title = "Sex"),
yaxis = list(title = "Tip"),
title = "Boxplot of Tip by Sex"
)
El grafico 17 volvemos a separar la muestra por sexo para exhibir el grafico de caja, en el cual, esta vez, apreciamos la media gracias a elementos como el ‘hover info’. Podemos hablar precisamente de una mediana en las mujeres de 2.75 y en los hombres de 3. Con respecto a la media,para las mujeres es de 2.8 y los hombres de 3.08.
fig <- plot_ly()
# Añadir la caja para Google
fig <- fig %>% add_boxplot(y = ~GOOG, data = csv, name = "Google",
boxpoints = "all", fillcolor = "blue", jitter = 0.5,
whiskerwidth = 0.2)
# Añadir la caja para Apple
fig <- fig %>% add_boxplot(y = ~AAPL, data = csv, name = "Apple",
boxpoints = "all", fillcolor = "red", jitter = 0.5,
whiskerwidth = 0.2)
# Definir el diseño del gráfico
fig <- fig %>% layout(
yaxis = list(title = "Value"),
title = "Boxplot of Google and Apple Stocks"
)
# Mostrar el gráfico
fig
Para el grafico 18 tenemos caja y bigotes junto con la dispersion. Para el precio de las acciones de Google hay una menor varianza, lo que corroboramos con la disprsion de los individuos, los cuales estan se ven todos agrupados en un mismo sector. A diferencia de las acciones de Apple, en donde hay una varianza mucho mayor y una mediana.
fig <- plot_ly(data = df_tips, y = ~total_bill, type = "violin", points = "all")
# Añadir el gráfico de caja y puntos
fig <- fig %>%
add_boxplot(y = ~total_bill, data = df_tips, name = "Box Plot")
# Mostrar el gráfico
fig
## Warning: 'box' objects don't have these attributes: 'points'
## Valid attributes include:
## 'alignmentgroup', 'boxmean', 'boxpoints', 'customdata', 'customdatasrc', 'dx', 'dy', 'fillcolor', 'hoverinfo', 'hoverinfosrc', 'hoverlabel', 'hoveron', 'hovertemplate', 'hovertemplatesrc', 'hovertext', 'hovertextsrc', 'ids', 'idssrc', 'jitter', 'legendgroup', 'legendgrouptitle', 'legendrank', 'line', 'lowerfence', 'lowerfencesrc', 'marker', 'mean', 'meansrc', 'median', 'mediansrc', 'meta', 'metasrc', 'name', 'notched', 'notchspan', 'notchspansrc', 'notchwidth', 'offsetgroup', 'opacity', 'orientation', 'pointpos', 'q1', 'q1src', 'q3', 'q3src', 'quartilemethod', 'sd', 'sdsrc', 'selected', 'selectedpoints', 'showlegend', 'stream', 'text', 'textsrc', 'transforms', 'type', 'uid', 'uirevision', 'unselected', 'upperfence', 'upperfencesrc', 'visible', 'whiskerwidth', 'width', 'x', 'x0', 'xaxis', 'xcalendar', 'xhoverformat', 'xperiod', 'xperiod0', 'xperiodalignment', 'xsrc', 'y', 'y0', 'yaxis', 'ycalendar', 'yhoverformat', 'yperiod', 'yperiod0', 'yperiodalignment', 'ysrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'
Para el grafico 19 notamos la dispersion de los datos, con un grafico de violin y un grafico de caja y bigotes. Apreciamos una mediana de 17.95, una varianza apreciable en el ancho de la caja, luego se nota como varios datos llegan a sobrepasar el bigote de las cajas.
fig_male <- plot_ly(data = subset(df_tips, sex == "Male"), y = ~tip, x = ~smoker,
title="MALE",type = "violin", boxpoints = "all") %>%
add_boxplot(y = ~tip, x = ~smoker, name = "Box Plot") %>%
layout(hovermode = "closest", title = "Male")
# Crear el gráfico de violín con cajas y puntos para el género femenino
fig_female <- plot_ly(data = subset(df_tips, sex == "Female"), y = ~tip, x = ~smoker,
title="FEMALE",type = "violin", boxpoints = "all") %>%
add_boxplot(y = ~tip, x = ~smoker, name = "Box Plot") %>%
layout(hovermode = "closest", title = "Female")
# Combinar los gráficos en una sola figura con dos columnas
fig <- subplot(fig_male, fig_female, nrows = 1,shareX = TRUE)
## Warning: 'violin' objects don't have these attributes: 'title', 'boxpoints'
## Valid attributes include:
## 'alignmentgroup', 'bandwidth', 'box', 'customdata', 'customdatasrc', 'fillcolor', 'hoverinfo', 'hoverinfosrc', 'hoverlabel', 'hoveron', 'hovertemplate', 'hovertemplatesrc', 'hovertext', 'hovertextsrc', 'ids', 'idssrc', 'jitter', 'legendgroup', 'legendgrouptitle', 'legendrank', 'line', 'marker', 'meanline', 'meta', 'metasrc', 'name', 'offsetgroup', 'opacity', 'orientation', 'pointpos', 'points', 'scalegroup', 'scalemode', 'selected', 'selectedpoints', 'showlegend', 'side', 'span', 'spanmode', 'stream', 'text', 'textsrc', 'transforms', 'type', 'uid', 'uirevision', 'unselected', 'visible', 'width', 'x', 'x0', 'xaxis', 'xhoverformat', 'xsrc', 'y', 'y0', 'yaxis', 'yhoverformat', 'ysrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'
## Warning: 'box' objects don't have these attributes: 'title'
## Valid attributes include:
## 'alignmentgroup', 'boxmean', 'boxpoints', 'customdata', 'customdatasrc', 'dx', 'dy', 'fillcolor', 'hoverinfo', 'hoverinfosrc', 'hoverlabel', 'hoveron', 'hovertemplate', 'hovertemplatesrc', 'hovertext', 'hovertextsrc', 'ids', 'idssrc', 'jitter', 'legendgroup', 'legendgrouptitle', 'legendrank', 'line', 'lowerfence', 'lowerfencesrc', 'marker', 'mean', 'meansrc', 'median', 'mediansrc', 'meta', 'metasrc', 'name', 'notched', 'notchspan', 'notchspansrc', 'notchwidth', 'offsetgroup', 'opacity', 'orientation', 'pointpos', 'q1', 'q1src', 'q3', 'q3src', 'quartilemethod', 'sd', 'sdsrc', 'selected', 'selectedpoints', 'showlegend', 'stream', 'text', 'textsrc', 'transforms', 'type', 'uid', 'uirevision', 'unselected', 'upperfence', 'upperfencesrc', 'visible', 'whiskerwidth', 'width', 'x', 'x0', 'xaxis', 'xcalendar', 'xhoverformat', 'xperiod', 'xperiod0', 'xperiodalignment', 'xsrc', 'y', 'y0', 'yaxis', 'ycalendar', 'yhoverformat', 'yperiod', 'yperiod0', 'yperiodalignment', 'ysrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'
## Warning: 'violin' objects don't have these attributes: 'title', 'boxpoints'
## Valid attributes include:
## 'alignmentgroup', 'bandwidth', 'box', 'customdata', 'customdatasrc', 'fillcolor', 'hoverinfo', 'hoverinfosrc', 'hoverlabel', 'hoveron', 'hovertemplate', 'hovertemplatesrc', 'hovertext', 'hovertextsrc', 'ids', 'idssrc', 'jitter', 'legendgroup', 'legendgrouptitle', 'legendrank', 'line', 'marker', 'meanline', 'meta', 'metasrc', 'name', 'offsetgroup', 'opacity', 'orientation', 'pointpos', 'points', 'scalegroup', 'scalemode', 'selected', 'selectedpoints', 'showlegend', 'side', 'span', 'spanmode', 'stream', 'text', 'textsrc', 'transforms', 'type', 'uid', 'uirevision', 'unselected', 'visible', 'width', 'x', 'x0', 'xaxis', 'xhoverformat', 'xsrc', 'y', 'y0', 'yaxis', 'yhoverformat', 'ysrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'
## Warning: 'box' objects don't have these attributes: 'title'
## Valid attributes include:
## 'alignmentgroup', 'boxmean', 'boxpoints', 'customdata', 'customdatasrc', 'dx', 'dy', 'fillcolor', 'hoverinfo', 'hoverinfosrc', 'hoverlabel', 'hoveron', 'hovertemplate', 'hovertemplatesrc', 'hovertext', 'hovertextsrc', 'ids', 'idssrc', 'jitter', 'legendgroup', 'legendgrouptitle', 'legendrank', 'line', 'lowerfence', 'lowerfencesrc', 'marker', 'mean', 'meansrc', 'median', 'mediansrc', 'meta', 'metasrc', 'name', 'notched', 'notchspan', 'notchspansrc', 'notchwidth', 'offsetgroup', 'opacity', 'orientation', 'pointpos', 'q1', 'q1src', 'q3', 'q3src', 'quartilemethod', 'sd', 'sdsrc', 'selected', 'selectedpoints', 'showlegend', 'stream', 'text', 'textsrc', 'transforms', 'type', 'uid', 'uirevision', 'unselected', 'upperfence', 'upperfencesrc', 'visible', 'whiskerwidth', 'width', 'x', 'x0', 'xaxis', 'xcalendar', 'xhoverformat', 'xperiod', 'xperiod0', 'xperiodalignment', 'xsrc', 'y', 'y0', 'yaxis', 'ycalendar', 'yhoverformat', 'yperiod', 'yperiod0', 'yperiodalignment', 'ysrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'
# Mostrar el gráfico
fig
## Warning: 'violin' objects don't have these attributes: 'title', 'boxpoints'
## Valid attributes include:
## 'alignmentgroup', 'bandwidth', 'box', 'customdata', 'customdatasrc', 'fillcolor', 'hoverinfo', 'hoverinfosrc', 'hoverlabel', 'hoveron', 'hovertemplate', 'hovertemplatesrc', 'hovertext', 'hovertextsrc', 'ids', 'idssrc', 'jitter', 'legendgroup', 'legendgrouptitle', 'legendrank', 'line', 'marker', 'meanline', 'meta', 'metasrc', 'name', 'offsetgroup', 'opacity', 'orientation', 'pointpos', 'points', 'scalegroup', 'scalemode', 'selected', 'selectedpoints', 'showlegend', 'side', 'span', 'spanmode', 'stream', 'text', 'textsrc', 'transforms', 'type', 'uid', 'uirevision', 'unselected', 'visible', 'width', 'x', 'x0', 'xaxis', 'xhoverformat', 'xsrc', 'y', 'y0', 'yaxis', 'yhoverformat', 'ysrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'
## Warning: 'box' objects don't have these attributes: 'title'
## Valid attributes include:
## 'alignmentgroup', 'boxmean', 'boxpoints', 'customdata', 'customdatasrc', 'dx', 'dy', 'fillcolor', 'hoverinfo', 'hoverinfosrc', 'hoverlabel', 'hoveron', 'hovertemplate', 'hovertemplatesrc', 'hovertext', 'hovertextsrc', 'ids', 'idssrc', 'jitter', 'legendgroup', 'legendgrouptitle', 'legendrank', 'line', 'lowerfence', 'lowerfencesrc', 'marker', 'mean', 'meansrc', 'median', 'mediansrc', 'meta', 'metasrc', 'name', 'notched', 'notchspan', 'notchspansrc', 'notchwidth', 'offsetgroup', 'opacity', 'orientation', 'pointpos', 'q1', 'q1src', 'q3', 'q3src', 'quartilemethod', 'sd', 'sdsrc', 'selected', 'selectedpoints', 'showlegend', 'stream', 'text', 'textsrc', 'transforms', 'type', 'uid', 'uirevision', 'unselected', 'upperfence', 'upperfencesrc', 'visible', 'whiskerwidth', 'width', 'x', 'x0', 'xaxis', 'xcalendar', 'xhoverformat', 'xperiod', 'xperiod0', 'xperiodalignment', 'xsrc', 'y', 'y0', 'yaxis', 'ycalendar', 'yhoverformat', 'yperiod', 'yperiod0', 'yperiodalignment', 'ysrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'
## Warning: 'violin' objects don't have these attributes: 'title', 'boxpoints'
## Valid attributes include:
## 'alignmentgroup', 'bandwidth', 'box', 'customdata', 'customdatasrc', 'fillcolor', 'hoverinfo', 'hoverinfosrc', 'hoverlabel', 'hoveron', 'hovertemplate', 'hovertemplatesrc', 'hovertext', 'hovertextsrc', 'ids', 'idssrc', 'jitter', 'legendgroup', 'legendgrouptitle', 'legendrank', 'line', 'marker', 'meanline', 'meta', 'metasrc', 'name', 'offsetgroup', 'opacity', 'orientation', 'pointpos', 'points', 'scalegroup', 'scalemode', 'selected', 'selectedpoints', 'showlegend', 'side', 'span', 'spanmode', 'stream', 'text', 'textsrc', 'transforms', 'type', 'uid', 'uirevision', 'unselected', 'visible', 'width', 'x', 'x0', 'xaxis', 'xhoverformat', 'xsrc', 'y', 'y0', 'yaxis', 'yhoverformat', 'ysrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'
## Warning: 'box' objects don't have these attributes: 'title'
## Valid attributes include:
## 'alignmentgroup', 'boxmean', 'boxpoints', 'customdata', 'customdatasrc', 'dx', 'dy', 'fillcolor', 'hoverinfo', 'hoverinfosrc', 'hoverlabel', 'hoveron', 'hovertemplate', 'hovertemplatesrc', 'hovertext', 'hovertextsrc', 'ids', 'idssrc', 'jitter', 'legendgroup', 'legendgrouptitle', 'legendrank', 'line', 'lowerfence', 'lowerfencesrc', 'marker', 'mean', 'meansrc', 'median', 'mediansrc', 'meta', 'metasrc', 'name', 'notched', 'notchspan', 'notchspansrc', 'notchwidth', 'offsetgroup', 'opacity', 'orientation', 'pointpos', 'q1', 'q1src', 'q3', 'q3src', 'quartilemethod', 'sd', 'sdsrc', 'selected', 'selectedpoints', 'showlegend', 'stream', 'text', 'textsrc', 'transforms', 'type', 'uid', 'uirevision', 'unselected', 'upperfence', 'upperfencesrc', 'visible', 'whiskerwidth', 'width', 'x', 'x0', 'xaxis', 'xcalendar', 'xhoverformat', 'xperiod', 'xperiod0', 'xperiodalignment', 'xsrc', 'y', 'y0', 'yaxis', 'ycalendar', 'yhoverformat', 'yperiod', 'yperiod0', 'yperiodalignment', 'ysrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'
Para el grafico 20 tenemos graficos de: violin, dispersion y caja y bigotes. Agrupamos los graficos con respecto a si los individuos fuman o no en relacion a las propinas. Entre fumadores y no fumadores vemos que no hay tanta diferencia en las varianzas de los sexos. Sin embargo, en ambos casos logramos ver como los fumadores llegan a tener un mayor valor en las propinas.
df_smoker_yes <- subset(df_tips, smoker == "Yes")
# Crear el gráfico de violín para fumadores
fig <- plot_ly(data = df_smoker_yes, x = ~day, y = ~total_bill, type = "violin",
legendgroup = "Yes", scalegroup = "Yes", name = "Yes", side = "negative",
line = list(color = "blue"))
# Mostrar el gráfico
fig
Para el grafico 21 tenemos un grafico de violin para cada dia, clasificado por las personas que si fuman en relacion al total de billetes. El mayor maximo se alcanza los sabados, el mayor minimo se encuentra los martes. Ademas, las medianas van desde las 16 unidades hasta las 23.
df_smoker_yes <- subset(df_tips, smoker == "Yes")
df_smoker_no <- subset(df_tips, smoker == "No")
# Crear el gráfico de violín para fumadores
plot_ly(data = df_smoker_yes, x = ~day, y = ~total_bill, type = "violin",
legendgroup = "Yes", scalegroup = "Yes", name = "Yes", side = "negative",
line = list(color = "blue")) %>%
add_trace(data = df_smoker_no, x = ~day, y = ~total_bill, type = "violin",
legendgroup = "No", scalegroup = "No", name = "No", side = "positive",
line = list(color = "red"))
Para el grafico 22 agregamos los no fumadores al grafico anterior. Vemos comportamientos parecidos. Sin embargo, el viernes vemos una diferencia en el rango que alcanza el total de billetes e incluso una mediana mayor para los no fumadores.
flights<-read.csv("https://raw.githubusercontent.com/lorenzog-ryzen/tasks_data_viz/main/flights.csv")
plot_ly(data = flights, x = ~year, y = ~month, z = ~passengers, type = "heatmap",
colorscale = "Viridis")
Para el grafico 23 tenemos un grafico de calor que contrasta los años con el mes, en donde ademas por el color clasificamos la cantidad de pasajeros en los vuelos. Se aprecia como con el pasar de los años la cantidad de los pasajeros aumenta. Ademas, julio parece ser el mes con mayor cantidad de pasajeros en todos los años.
plot_ly(flights, x = ~year, y = ~month, z = ~passengers, type = "scatter3d",
color = ~year, colors = c("blue", "green", "red"), opacity = 0.7) %>%
layout(
width = 800,
height = 400,
scene = list(
xaxis = list(title = "Año"),
yaxis = list(title = "Mes"),
zaxis = list(title = "Pasajeros")
)
)
## Warning: Specifying width/height in layout() is now deprecated.
## Please specify in ggplotly() or plot_ly()
## No scatter3d mode specifed:
## Setting the mode to markers
## Read more about this attribute -> https://plotly.com/r/reference/#scatter-mode
Para el grafico 24 tenemos tres dimensiones. Algo parecido a lo que es el heatmap, en cuanto a la relacion: año-mes-cantidad de pasajeros. Ademas, pordemos apreciar de otra forma como los pasajeros aumentan con los años.
plot_ly(flights, x = ~year, y = ~month, z = ~passengers, type = "scatter3d",
mode = "lines+markers", color = ~year, colors = c("blue", "green", "red"), opacity = 0.7) %>%
layout(
width = 800,
height = 400,
scene = list(
xaxis = list(title = "Año"),
yaxis = list(title = "Mes"),
zaxis = list(title = "Pasajeros")
)
)
## Warning: Specifying width/height in layout() is now deprecated.
## Please specify in ggplotly() or plot_ly()
Para el grafico 25 tenemos otroa apreciacion en tres dimensiones de año-mes-cantidad de pasajeros. pero esta vez conecatamos los puntos con lineas para que se asemeje mas a una funcion rectangular.
ggpairs(flights, aes(color = month))
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
Para el grafico 26 tenemos una matriz de graficos en donde encontramos: distribuciones, correlaciones, cajas, etc. En todas se logra apreciar esa correlacion directa entre el tiempo y la cantidad de pasajeros.
df<-read.csv("https://raw.githubusercontent.com/lorenzog-ryzen/tasks_data_viz/main/df.csv")
fig <- plot_ly(data = df, type = "scattergeo", locationmode = "ISO-3") %>%
add_trace(
x = ~gdpPercap,
y = ~lifeExp,
color = ~continent,
text = ~country,
sizes = ~pop,
marker = list(sizemode = "area", sizeref = 200000)
) %>%
layout(
title = "Scatter Geo Plot",
geo = list(
projection = list(type = "orthographic"),
showland = TRUE,
landcolor = toRGB("gray"),
showcountries = TRUE
)
)
fig
## No scattergeo mode specifed:
## Setting the mode to markers
## Read more about this attribute -> https://plotly.com/r/reference/#scatter-mode
## No scattergeo mode specifed:
## Setting the mode to markers
## Read more about this attribute -> https://plotly.com/r/reference/#scatter-mode
Para el grafico 27 tenemos una aprecicion en 3d del planeta. GGracias a esto apreciamos mejor la distribucion de los datos entre los contintentes. Vemos como estos se agrupan en la parte superior del planeta (polo norte).
df_wind<-read.csv("https://raw.githubusercontent.com/lorenzog-ryzen/tasks_data_viz/main/df_wind.csv")
plot_ly(df_wind,
r = ~frequency,
theta = ~direction,
color = ~strength,
size = ~frequency,
symbol = ~strength,
type = "scatterpolar")
## No scatterpolar mode specifed:
## Setting the mode to markers
## Read more about this attribute -> https://plotly.com/r/reference/#scatter-mode
## Warning: The shape palette can deal with a maximum of 6 discrete values because more
## than 6 becomes difficult to discriminate
## ℹ you have requested 8 values. Consider specifying shapes manually if you need
## that many have them.
## Warning: The following are not valid symbol codes:
## 'NA'
## Valid symbols include:
## '0', '0', 'circle', '100', '100', 'circle-open', '200', '200', 'circle-dot', '300', '300', 'circle-open-dot', '1', '1', 'square', '101', '101', 'square-open', '201', '201', 'square-dot', '301', '301', 'square-open-dot', '2', '2', 'diamond', '102', '102', 'diamond-open', '202', '202', 'diamond-dot', '302', '302', 'diamond-open-dot', '3', '3', 'cross', '103', '103', 'cross-open', '203', '203', 'cross-dot', '303', '303', 'cross-open-dot', '4', '4', 'x', '104', '104', 'x-open', '204', '204', 'x-dot', '304', '304', 'x-open-dot', '5', '5', 'triangle-up', '105', '105', 'triangle-up-open', '205', '205', 'triangle-up-dot', '305', '305', 'triangle-up-open-dot', '6', '6', 'triangle-down', '106', '106', 'triangle-down-open', '206', '206', 'triangle-down-dot', '306', '306', 'triangle-down-open-dot', '7', '7', 'triangle-left', '107', '107', 'triangle-left-open', '207', '207', 'triangle-left-dot', '307', '307', 'triangle-left-open-dot', '8', '8', 'triangle-right', '108', '108', 'triangle-right-open', '208', '208', 'triangle-right-dot', '308', '308', 'triangle-right-open-dot', '9', '9', 'triangle-ne', '109', '109', 'triangle-ne-open', '209', '209', 'triangle-ne-dot', '309', '309', 'triangle-ne-open-dot', '10', '10', 'triangle-se', '110', '110', 'triangle-se-open', '210', '210', 'triangle-se-dot', '310', '310', 'triangle-se-open-dot', '11', '11', 'triangle-sw', '111', '111', 'triangle-sw-open', '211', '211', 'triangle-sw-dot', '311', '311', 'triangle-sw-open-dot', '12', '12', 'triangle-nw', '112', '112', 'triangle-nw-open', '212', '212', 'triangle-nw-dot', '312', '312', 'triangle-nw-open-dot', '13', '13', 'pentagon', '113', '113', 'pentagon-open', '213', '213', 'pentagon-dot', '313', '313', 'pentagon-open-dot', '14', '14', 'hexagon', '114', '114', 'hexagon-open', '214', '214', 'hexagon-dot', '314', '314', 'hexagon-open-dot', '15', '15', 'hexagon2', '115', '115', 'hexagon2-open', '215', '215', 'hexagon2-dot', '315', '315', 'hexagon2-open-dot', '16', '16', 'octagon', '116', '116', 'octagon-open', '216', '216', 'octagon-dot', '316', '316', 'octagon-open-dot', '17', '17', 'star', '117', '117', 'star-open', '217', '217', 'star-dot', '317', '317', 'star-open-dot', '18', '18', 'hexagram', '118', '118', 'hexagram-open', '218', '218', 'hexagram-dot', '318', '318', 'hexagram-open-dot', '19', '19', 'star-triangle-up', '119', '119', 'star-triangle-up-open', '219', '219', 'star-triangle-up-dot', '319', '319', 'star-triangle-up-open-dot', '20', '20', 'star-triangle-down', '120', '120', 'star-triangle-down-open', '220', '220', 'star-triangle-down-dot', '320', '320', 'star-triangle-down-open-dot', '21', '21', 'star-square', '121', '121', 'star-square-open', '221', '221', 'star-square-dot', '321', '321', 'star-square-open-dot', '22', '22', 'star-diamond', '122', '122', 'star-diamond-open', '222', '222', 'star-diamond-dot', '322', '322', 'star-diamond-open-dot', '23', '23', 'diamond-tall', '123', '123', 'diamond-tall-open', '223', '223', 'diamond-tall-dot', '323', '323', 'diamond-tall-open-dot', '24', '24', 'diamond-wide', '124', '124', 'diamond-wide-open', '224', '224', 'diamond-wide-dot', '324', '324', 'diamond-wide-open-dot', '25', '25', 'hourglass', '125', '125', 'hourglass-open', '26', '26', 'bowtie', '126', '126', 'bowtie-open', '27', '27', 'circle-cross', '127', '127', 'circle-cross-open', '28', '28', 'circle-x', '128', '128', 'circle-x-open', '29', '29', 'square-cross', '129', '129', 'square-cross-open', '30', '30', 'square-x', '130', '130', 'square-x-open', '31', '31', 'diamond-cross', '131', '131', 'diamond-cross-open', '32', '32', 'diamond-x', '132', '132', 'diamond-x-open', '33', '33', 'cross-thin', '133', '133', 'cross-thin-open', '34', '34', 'x-thin', '134', '134', 'x-thin-open', '35', '35', 'asterisk', '135', '135', 'asterisk-open', '36', '36', 'hash', '136', '136', 'hash-open', '236', '236', 'hash-dot', '336', '336', 'hash-open-dot', '37', '37', 'y-up', '137', '137', 'y-up-open', '38', '38', 'y-down', '138', '138', 'y-down-open', '39', '39', 'y-left', '139', '139', 'y-left-open', '40', '40', 'y-right', '140', '140', 'y-right-open', '41', '41', 'line-ew', '141', '141', 'line-ew-open', '42', '42', 'line-ns', '142', '142', 'line-ns-open', '43', '43', 'line-ne', '143', '143', 'line-ne-open', '44', '44', 'line-nw', '144', '144', 'line-nw-open', '45', '45', 'arrow-up', '145', '145', 'arrow-up-open', '46', '46', 'arrow-down', '146', '146', 'arrow-down-open', '47', '47', 'arrow-left', '147', '147', 'arrow-left-open', '48', '48', 'arrow-right', '148', '148', 'arrow-right-open', '49', '49', 'arrow-bar-up', '149', '149', 'arrow-bar-up-open', '50', '50', 'arrow-bar-down', '150', '150', 'arrow-bar-down-open', '51', '51', 'arrow-bar-left', '151', '151', 'arrow-bar-left-open', '52', '52', 'arrow-bar-right', '152', '152', 'arrow-bar-right-open
## Warning: The following are not valid symbol codes:
## 'NA'
## Valid symbols include:
## '0', '0', 'circle', '100', '100', 'circle-open', '200', '200', 'circle-dot', '300', '300', 'circle-open-dot', '1', '1', 'square', '101', '101', 'square-open', '201', '201', 'square-dot', '301', '301', 'square-open-dot', '2', '2', 'diamond', '102', '102', 'diamond-open', '202', '202', 'diamond-dot', '302', '302', 'diamond-open-dot', '3', '3', 'cross', '103', '103', 'cross-open', '203', '203', 'cross-dot', '303', '303', 'cross-open-dot', '4', '4', 'x', '104', '104', 'x-open', '204', '204', 'x-dot', '304', '304', 'x-open-dot', '5', '5', 'triangle-up', '105', '105', 'triangle-up-open', '205', '205', 'triangle-up-dot', '305', '305', 'triangle-up-open-dot', '6', '6', 'triangle-down', '106', '106', 'triangle-down-open', '206', '206', 'triangle-down-dot', '306', '306', 'triangle-down-open-dot', '7', '7', 'triangle-left', '107', '107', 'triangle-left-open', '207', '207', 'triangle-left-dot', '307', '307', 'triangle-left-open-dot', '8', '8', 'triangle-right', '108', '108', 'triangle-right-open', '208', '208', 'triangle-right-dot', '308', '308', 'triangle-right-open-dot', '9', '9', 'triangle-ne', '109', '109', 'triangle-ne-open', '209', '209', 'triangle-ne-dot', '309', '309', 'triangle-ne-open-dot', '10', '10', 'triangle-se', '110', '110', 'triangle-se-open', '210', '210', 'triangle-se-dot', '310', '310', 'triangle-se-open-dot', '11', '11', 'triangle-sw', '111', '111', 'triangle-sw-open', '211', '211', 'triangle-sw-dot', '311', '311', 'triangle-sw-open-dot', '12', '12', 'triangle-nw', '112', '112', 'triangle-nw-open', '212', '212', 'triangle-nw-dot', '312', '312', 'triangle-nw-open-dot', '13', '13', 'pentagon', '113', '113', 'pentagon-open', '213', '213', 'pentagon-dot', '313', '313', 'pentagon-open-dot', '14', '14', 'hexagon', '114', '114', 'hexagon-open', '214', '214', 'hexagon-dot', '314', '314', 'hexagon-open-dot', '15', '15', 'hexagon2', '115', '115', 'hexagon2-open', '215', '215', 'hexagon2-dot', '315', '315', 'hexagon2-open-dot', '16', '16', 'octagon', '116', '116', 'octagon-open', '216', '216', 'octagon-dot', '316', '316', 'octagon-open-dot', '17', '17', 'star', '117', '117', 'star-open', '217', '217', 'star-dot', '317', '317', 'star-open-dot', '18', '18', 'hexagram', '118', '118', 'hexagram-open', '218', '218', 'hexagram-dot', '318', '318', 'hexagram-open-dot', '19', '19', 'star-triangle-up', '119', '119', 'star-triangle-up-open', '219', '219', 'star-triangle-up-dot', '319', '319', 'star-triangle-up-open-dot', '20', '20', 'star-triangle-down', '120', '120', 'star-triangle-down-open', '220', '220', 'star-triangle-down-dot', '320', '320', 'star-triangle-down-open-dot', '21', '21', 'star-square', '121', '121', 'star-square-open', '221', '221', 'star-square-dot', '321', '321', 'star-square-open-dot', '22', '22', 'star-diamond', '122', '122', 'star-diamond-open', '222', '222', 'star-diamond-dot', '322', '322', 'star-diamond-open-dot', '23', '23', 'diamond-tall', '123', '123', 'diamond-tall-open', '223', '223', 'diamond-tall-dot', '323', '323', 'diamond-tall-open-dot', '24', '24', 'diamond-wide', '124', '124', 'diamond-wide-open', '224', '224', 'diamond-wide-dot', '324', '324', 'diamond-wide-open-dot', '25', '25', 'hourglass', '125', '125', 'hourglass-open', '26', '26', 'bowtie', '126', '126', 'bowtie-open', '27', '27', 'circle-cross', '127', '127', 'circle-cross-open', '28', '28', 'circle-x', '128', '128', 'circle-x-open', '29', '29', 'square-cross', '129', '129', 'square-cross-open', '30', '30', 'square-x', '130', '130', 'square-x-open', '31', '31', 'diamond-cross', '131', '131', 'diamond-cross-open', '32', '32', 'diamond-x', '132', '132', 'diamond-x-open', '33', '33', 'cross-thin', '133', '133', 'cross-thin-open', '34', '34', 'x-thin', '134', '134', 'x-thin-open', '35', '35', 'asterisk', '135', '135', 'asterisk-open', '36', '36', 'hash', '136', '136', 'hash-open', '236', '236', 'hash-dot', '336', '336', 'hash-open-dot', '37', '37', 'y-up', '137', '137', 'y-up-open', '38', '38', 'y-down', '138', '138', 'y-down-open', '39', '39', 'y-left', '139', '139', 'y-left-open', '40', '40', 'y-right', '140', '140', 'y-right-open', '41', '41', 'line-ew', '141', '141', 'line-ew-open', '42', '42', 'line-ns', '142', '142', 'line-ns-open', '43', '43', 'line-ne', '143', '143', 'line-ne-open', '44', '44', 'line-nw', '144', '144', 'line-nw-open', '45', '45', 'arrow-up', '145', '145', 'arrow-up-open', '46', '46', 'arrow-down', '146', '146', 'arrow-down-open', '47', '47', 'arrow-left', '147', '147', 'arrow-left-open', '48', '48', 'arrow-right', '148', '148', 'arrow-right-open', '49', '49', 'arrow-bar-up', '149', '149', 'arrow-bar-up-open', '50', '50', 'arrow-bar-down', '150', '150', 'arrow-bar-down-open', '51', '51', 'arrow-bar-left', '151', '151', 'arrow-bar-left-open', '52', '52', 'arrow-bar-right', '152', '152', 'arrow-bar-right-open
## Warning: `line.width` does not currently support multiple values.
## Warning: `line.width` does not currently support multiple values.
## Warning: `line.width` does not currently support multiple values.
## Warning: `line.width` does not currently support multiple values.
## Warning: `line.width` does not currently support multiple values.
## Warning: `line.width` does not currently support multiple values.
## Warning: `line.width` does not currently support multiple values.
## Warning: `line.width` does not currently support multiple values.
df_wind$direction <- factor(df_wind$direction, levels = c("N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW"))
# Crear el gráfico polar de líneas
fig <- plot_ly(df_wind, type = 'scatterpolar', mode = 'lines',
r = ~frequency, theta = ~direction, color = ~strength,
colors = c("blue", "green", "red"),
line = list(shape = "linear"),
width = 800, height = 400)
# Mostrar el gráfico
fig
En los dos ultimos graficos tenemos dos distintas apreciaciones de lo mismo. En una escala polar, que se usa para apreciar mejor la direccion del vientom, se contrastan estas variables y al mismo tiempo se clasifican por su color en base a la fuerza del viento. El primer enfoque se hace con ‘puntos’ y el ultimo con ‘lineas’.
df_exp <- read.csv("https://raw.githubusercontent.com/lorenzog-ryzen/tasks_data_viz/main/df_exp.csv")
# Crear el gráfico ternario
fig <- plot_ly(df_exp, type = "scatterternary", mode = "markers",
a = ~experiment_1, b = ~experiment_2, c = ~experiment_3,
color = ~gender, symbol = ~gender,
colors = c("blue", "red"),
marker = list(size = 10),
hoverinfo = "text",
text = ~paste("Group: ", group, "<br>Gender: ", gender))
# Mostrar el gráfico
fig
Para este grafico tomamos como representacion una piramide. contrastamos los resultados de tres experimentos, diferenciamos por sexo. Seria una grafica poligonal para encontrar el acercamiento de la informacion entre las variables. Finalmente, apreciamos que todos los resultados se agrupan alrededor de los 0.4 y 0.6, sin importar el sexo.
df_male <- df_tips[df_tips$sex == "Male", ]
df_female <- df_tips[df_tips$sex == "Female", ]
# Crear subgráficos
p_male <- plot_ly(df_male, x = ~total_bill, y = ~tip, color = ~smoker, type = "scatter", mode = "markers") %>%
layout(title = "Relación entre total_bill y tip para hombres",
xaxis = list(title = "Total Bill"),
yaxis = list(title = "Tip"))
p_female <- plot_ly(df_female, x = ~total_bill, y = ~tip, color = ~smoker, type = "scatter", mode = "markers") %>%
layout(title = "Relación entre total_bill y tip ",
xaxis = list(title = "Total Bill"),
yaxis = list(title = "Tip"))
# Mostrar subgráficos
subplot(p_male, p_female)
## Warning in RColorBrewer::brewer.pal(N, "Set2"): minimal value for n is 3, returning requested palette with 3 different levels
## Warning in RColorBrewer::brewer.pal(N, "Set2"): minimal value for n is 3, returning requested palette with 3 different levels
## Warning in RColorBrewer::brewer.pal(N, "Set2"): minimal value for n is 3, returning requested palette with 3 different levels
## Warning in RColorBrewer::brewer.pal(N, "Set2"): minimal value for n is 3, returning requested palette with 3 different levels
Para ambos sexos contrastamos el total de billetes y las propinas. Facilmente se aprecia un comportamiento similar entre ambas graficas. Se aprecia la linealidad entre las varibles. Sin embargo, para corrborar esto fielmente hace falta un prueba de correlacion.
att_df<-read.csv("https://raw.githubusercontent.com/lorenzog-ryzen/tasks_data_viz/main/att_df.csv")
ggplot(df_tips, aes(x = total_bill, fill = sex)) +
geom_histogram(binwidth = 2, position = "dodge") +
facet_grid(rows = vars(time), cols = vars(day), scales = "free") +
labs(x = "Total Bill", y = "Sum of tip", fill = "Sex",
title = "Histogram of Tips by Sex, Day, and Time") +
theme_minimal()
Ahora tomamos distintos histogramas. Estos los clasificamos por sexo, dia y tiempo. Se sigue apreciando como los fines de semana los datos toman valores maoyres. Ademas, Los hombres siempre obtienen igual o mas en el total de la propina.