Resumen de plataformas usadas por Donald trump

Se puede apreciar uqe la plataforma preferida por el publico apra ver los tweets de Donald Trump siendo la web directa de Twitter el favorito por el publico.

Tweet mas reposteado

Como sabemos Trump tiene una cierta popularidad en Twitter, y aqui estan sus top 5 tweets

source text retweet_count
Twitter for iPhone #FraudNewsCNN #FNN https://t.co/WYUnHjjUjg 369530
Twitter for Android TODAY WE MAKE AMERICA GREAT AGAIN! 344806
Twitter Web Client Why would Kim Jong-un insult me by calling me “old,” when I would NEVER call him “short and fat?” Oh well, I try so hard to be his friend - and maybe someday that will happen! 272776
Twitter for Android Such a beautiful and important evening! The forgotten man and woman will never be forgotten again. We will all come together as never before 220796
Twitter for iPhone How long did it take your staff of 823 people to think that up–and where are your 33,000 emails that you deleted? https://t.co/gECLNtQizQ 168765

Favoritos por plataforma

Aqui hay otra grafica donde podemos ver en que plataforma ha obtenido mas favoritos en la plataforma de twitter.

library(ggplot2)
library(dplyr)

# Datos para el primer gráfico de pie
datos1 <- pajarito %>%
  filter(source %in% c("Twitter for iPhone", "Twitter for Android", "Twitter Web Client", 
                       "Media Studio", "Twitter Ads", "Twitter for iPad", "Instagram")) %>%
  group_by(source) %>%
  summarise(total_favorites = sum(favorite_count, na.rm = TRUE)) %>%
  mutate(percentage = total_favorites / sum(total_favorites) * 100) %>%
  arrange(desc(total_favorites)) %>%
  mutate(label = paste0(source, ": ", round(percentage, 1), "%"))

# Crear el primer gráfico de pie
ggplot(datos1, aes(x = "", y = total_favorites, fill = label)) +
  geom_bar(stat = "identity", width = 1) +
  coord_polar("y", start = 0) +
  theme_void() +
  labs(title = "Favoritos por plataforma (Plataformas Principales)") +
  theme(legend.position = "right") +
  guides(fill = guide_legend(title = "Plataforma", 
                             label.position = "right", 
                             label.hjust = 1))

Debido a la popularidad tan grande de Twitter en la plataforma de iPhone, el siguiente graficommostrara las otras plataformas que son usadas por los usuarios de Twitter.

library(ggplot2)
library(dplyr)

# Datos para el segundo gráfico de pie
datos2 <- pajarito %>%
  filter(source %in% c("TweetDeck", "Twitter for BlackBerry", "Periscope", "Twitter QandA", 
                       "Facebook", "TwitLonger Beta", "Mobile Web (M5)", "Twitter Mirror for iPad", 
                       "Vine - Make a Scene", "Twitlonger", "Neatly For BlackBerry 10", "Twitter for Websites")) %>%
  group_by(source) %>%
  summarise(total_favorites = sum(favorite_count, na.rm = TRUE)) %>%
  mutate(percentage = total_favorites / sum(total_favorites) * 100) %>%
  arrange(desc(total_favorites)) %>%
  mutate(label = paste0(source, ": ", round(percentage, 1), "%"))

# Crear el segundo gráfico de pie
ggplot(datos2, aes(x = "", y = total_favorites, fill = label)) +
  geom_bar(stat = "identity", width = 1) +
  coord_polar("y", start = 0) +
  theme_void() +
  labs(title = "Favoritos por plataforma (Otras Plataformas)") +
  theme(legend.position = "right") +
  guides(fill = guide_legend(title = "Plataforma", 
                             label.position = "right", 
                             label.hjust = 1))

library(ggplot2)
library(dplyr)

# Datos para el primer gráfico de barras
datos1 <- pajarito %>%
  filter(source %in% c("Twitter for iPhone", "Twitter for Android", "Twitter Web Client", 
                       "Media Studio", "Twitter Ads", "Twitter for iPad", "Instagram")) %>%
  group_by(source) %>%
  summarise(total_favorites = sum(favorite_count, na.rm = TRUE)) %>%
  arrange(desc(total_favorites))

# Crear el primer gráfico de barras
ggplot(datos1, aes(x = reorder(source, -total_favorites), y = total_favorites, fill = source)) +
  geom_bar(stat = "identity") +
  theme_minimal() +
  labs(title = "Favoritos por plataforma (Plataformas Principales)",
       x = "Plataforma",
       y = "Total de Favoritos") +
  theme(legend.position = "none") +
  geom_text(aes(label = total_favorites), vjust = -0.3)

Otra vez como se peude apreciar en la grafica, la presencia de Twitter iPhone es demaciado usada por lo que haremos uso de otro grafico para analizar otras plataformas:

# Crear la tabla de frecuencias excluyendo "Twitter for iPhone"
tabla_plataforma <- table(pajarito$source)
tabla_plataforma <- tabla_plataforma[names(tabla_plataforma) != "Twitter for iPhone"]

# Crear el gráfico de barras
barplot(tabla_plataforma, main = "Gráfico de barras",
        ylab = "Frecuencia", xlab = "Plataforma",
        ylim = c(0, 12000), col = brewer.pal(4, "Set1"), border = brewer.pal(4, "Set1"))
grid(nx = NA, ny = NULL, col = "lightgray", lty = "dotted", lwd = par("lwd"))

library(ggplot2)
library(dplyr)

# Datos para el histograma de plataformas principales
datos1 <- pajarito %>%
  filter(source %in% c("Twitter for iPhone", "Twitter for Android", "Twitter Web Client", 
                       "Media Studio", "Twitter Ads", "Twitter for iPad", "Instagram"))

# Crear el histograma
ggplot(datos1, aes(x = favorite_count)) +
  geom_histogram(binwidth = 10, fill = "skyblue", color = "black", width = 0.9) +  # Ajustar el ancho de las barras
  labs(title = "Histograma de Favoritos (Plataformas Principales)",
       x = "Número de Favoritos",
       y = "Frecuencia") +
  theme_minimal() +
  theme(plot.title = element_text(size = 20),
        axis.title = element_text(size = 15),
        axis.text = element_text(size = 12),
        axis.text.x = element_text(angle = 45, hjust = 1)) +
  scale_x_continuous(limits = c(0, 100))  # Ajustar los límites del eje X
## Warning: Removed 11319 rows containing non-finite outside the scale range
## (`stat_bin()`).
## Warning: Removed 2 rows containing missing values or values outside the scale range
## (`geom_bar()`).

Se puede apreciar en este grafico que aqui mayormente se ponen favoritos atravez de la plataforma de Web de twitter.

library(ggplot2)
library(dplyr)

# Datos para el histograma de plataformas principales
datos1 <- pajarito %>%
  filter(source %in% c("TweetDeck", "Twitter for BlackBerry", "Periscope", "Twitter QandA", 
                       "Facebook", "TwitLonger Beta", "Mobile Web (M5)", "Twitter Mirror for iPad", 
                       "Vine - Make a Scene", "Twitlonger", "Neatly For BlackBerry 10", "Twitter for Websites"))

# Crear el histograma
ggplot(datos1, aes(x = favorite_count)) +
  geom_histogram(binwidth = 10, fill = "skyblue", color = "black", width = 0.9) +  # Ajustar el ancho de las barras
  labs(title = "Histograma de Favoritos (Plataformas Principales)",
       x = "Número de Favoritos",
       y = "Frecuencia") +
  theme_minimal() +
  theme(plot.title = element_text(size = 20),
        axis.title = element_text(size = 15),
        axis.text = element_text(size = 12)) +
  scale_x_continuous(limits = c(0, 100))  # Ajustar los límites del eje X
## Warning: Removed 168 rows containing non-finite outside the scale range
## (`stat_bin()`).
## Warning: Removed 2 rows containing missing values or values outside the scale range
## (`geom_bar()`).

library(ggplot2)
library(dplyr)

# Datos para el histograma de plataformas principales
datos1 <- pajarito %>%
  filter(source %in% c("Twitter for iPhone", "Twitter for Android", "Twitter Web Client", 
                       "Media Studio", "Twitter Ads", "Twitter for iPad", "Instagram"))

# Calcular el número de bins usando la regla de Sturges
num_bins <- nclass.Sturges(datos1$favorite_count)

# Crear el histograma con línea de densidad
ggplot(datos1, aes(x = favorite_count)) +
  geom_histogram(aes(y = ..density..), bins = num_bins, fill = "skyblue", color = "black", width = 0.9) +  # Ajustar el ancho de las barras
  geom_density(color = "red", size = 1) +  # Añadir línea de densidad
  labs(title = "Histograma de Favoritos (Plataformas Principales)",
       x = "Número de Favoritos",
       y = "Densidad") +
  theme_minimal() +
  theme(plot.title = element_text(size = 20),
        axis.title = element_text(size = 15),
        axis.text = element_text(size = 12),
        axis.text.x = element_text(angle = 45, hjust = 1)) +
  scale_x_continuous(limits = c(0, 100))  # Ajustar los límites del eje X
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## Warning: The dot-dot notation (`..density..`) was deprecated in ggplot2 3.4.0.
## ℹ Please use `after_stat(density)` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## Warning: Removed 11319 rows containing non-finite outside the scale range
## (`stat_bin()`).
## Warning: Removed 11319 rows containing non-finite outside the scale range
## (`stat_density()`).
## Warning: Removed 2 rows containing missing values or values outside the scale range
## (`geom_bar()`).

Debido a la inmensidad de la densidad en la plataforma de twitter para iphone la grafica tiende a sobre salirse sin embargo mantiene sus constnacia con las oytras graficas.

library(ggplot2)
library(dplyr)

# Datos para el histograma de plataformas principales
datos1 <- pajarito %>%
  filter(source %in% c("TweetDeck", "Twitter for BlackBerry", "Periscope", "Twitter QandA", 
                       "Facebook", "TwitLonger Beta", "Mobile Web (M5)", "Twitter Mirror for iPad", 
                       "Vine - Make a Scene", "Twitlonger", "Neatly For BlackBerry 10", "Twitter for Websites"))

# Calcular el número de bins usando la regla de Sturges
num_bins <- nclass.Sturges(datos1$favorite_count)

# Crear el histograma con línea de densidad
ggplot(datos1, aes(x = favorite_count)) +
  geom_histogram(aes(y = ..density..), bins = num_bins, fill = "skyblue", color = "black", width = 0.9) +  # Ajustar el ancho de las barras
  geom_density(color = "red", size = 1) +  # Añadir línea de densidad
  labs(title = "Histograma de Favoritos (Plataformas Principales)",
       x = "Número de Favoritos",
       y = "Densidad") +
  theme_minimal() +
  theme(plot.title = element_text(size = 20),
        axis.title = element_text(size = 15),
        axis.text = element_text(size = 12)) +
  scale_x_continuous(limits = c(0, 100))  # Ajustar los límites del eje X
## Warning: Removed 168 rows containing non-finite outside the scale range
## (`stat_bin()`).
## Warning: Removed 168 rows containing non-finite outside the scale range
## (`stat_density()`).
## Warning: Removed 2 rows containing missing values or values outside the scale range
## (`geom_bar()`).

Finalmente esta grafica que son las aplicaciones menos usados por los usuarios hay un mayor equilibrio ya que la escala entre ellas no es tan grande como las graficas anteriores.

Histograma

Definición:

Un histograma es una representación gráfica de la distribución de un conjunto de datos. Se divide el rango de los datos en intervalos (o “bins”) y se cuenta cuántos valores caen en cada intervalo.

Visualización:

Se muestra como una serie de barras verticales, donde la altura de cada barra representa la frecuencia (o el número de observaciones) en cada intervalo.

Uso:

Es útil para visualizar la distribución de datos discretos o continuos y para identificar patrones como la simetría, la asimetría, la presencia de picos, etc.

Curva de Densidad

Definición:

Una curva de densidad es una estimación suave de la función de densidad de probabilidad de una variable aleatoria continua. Representa la probabilidad de que una variable tome un valor dentro de un rango específico.

Visualización:

Se muestra como una línea suave que sigue la forma de la distribución de los datos. La integral bajo la curva es igual a 1, lo que representa la probabilidad total.

Uso:

Es útil para visualizar la distribución de datos continuos y para comparar distribuciones. A diferencia del histograma, no depende del número de bins y proporciona una representación más suave y continua de los datos.