I have a database with a sample im working on. Im trying to get the code to add all the earnings for each variable (12 variables) and then display on top of each column an abbreviated version of the number because it is in the billions and it is two long. The problem seems to be that I can't use count because I have x and y in aesthetics, but if I cut one out then I can't make the graph. This is my code:
set.seed(180173)
renglones <- sample(1:nrow(Metro), size=300, replace = FALSE)
MuestraNE <- Metro[renglones, ]
View (MuestraNE)
summary(MuestraNE)
library(ggplot2)
library(reshape2)
ing = aggregate(.~ TIPO_INGRESO, FUN = sum, data=MuestraNE)
tot = colSums(ing[,3:14])
lblstot = c(tot[1]/100000000,tot[2]/100000000,tot[3]/100000000,tot[4]/100000000,
tot[5]/100000000,tot[6]/100000000,tot[7]/100000000,tot[8]/100000000,
tot[9]/100000000,tot[10]/100000000,tot[11]/100000000,tot[12]/100000000)
p <- as.numeric(lblstot)
gg <- melt(MuestraNE[ , 3:14])
ggplot(gg, aes(x=variable, y=value)) +
geom_bar(fill = "orange", stat = "identity") +
ggtitle("Total por Línea de Metro")+
geom_text(aes(y = p), vjust=-1, size = 3)+
theme(axis.title = element_blank(), legend.position = "none",
plot.title = element_text(hjust = 0.5, face = "bold"),
axis.ticks = element_blank(), axis.text.y = element_blank(),
axis.text.x = element_text(angle = 270, vjust = 0.3, hjust = -0.5,
color = "black"))
whenever I try to add some kind of format with geom_text() I always get an error saying:
Error: Aesthetics must be either length 1 or the same as the data (3600): y
Run `rlang::last_error()` to see where the error occurred.
I've tried everything I could find on google and in here but nothing seems to work, I's appreciate a lot if you guys could help me out. This is the link to my database The libstot part is what I'm trying to get on top of each column, i.e. tot1/10000000 on top of the first column, tot[2]/100000000 on top of the second column etcetera.