Skip to content

Instantly share code, notes, and snippets.

@jspaezp
Last active February 9, 2017 02:52
Show Gist options
  • Save jspaezp/f0072ea4620ee1aef750d8ff33011e19 to your computer and use it in GitHub Desktop.
Save jspaezp/f0072ea4620ee1aef750d8ff33011e19 to your computer and use it in GitHub Desktop.
# Generacion de los datos
x <- runif(20) + 1
y <- rep(c('a','b', 'c', 'd'), 5)
z <- rep(c('FACTOR 1','FACTOR 2'), 5)
# hacer el DF
my_data <- data.frame(x1 = sample(x), y1 = y, z1 = z)
# Cargar los paquetes
require(ggplot2)
require(dplyr)
# Este grafico muestra las lineas en el medio de la barra
my_data
g <- ggplot(my_data, aes(x = y1, y = x1, fill = z1))
g <- g + geom_bar(stat = 'identity', position = position_dodge(), colour = 'black')
g
my_data2 <- my_data %>% group_by(y1,z1) %>% summarise(x1 = mean(x1))
my_data2
# Este grafico muestra como dejan de aparecer cuando se tiene solo la media
g <- ggplot(my_data2, aes(x = y1, y = x1, fill = z1, group = interaction(y1,z1)))
g <- g + geom_bar(stat = 'identity', position = position_dodge(), colour = 'black')
g
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment