Cómo agregar etiquetas de datos a ggplot
Intentar agregar etiquetas de datos a un diagrama de barras, usar ggplot me está dando el siguiente error:
Error: geom_text requires the following missing aesthetics: x
Mis datos de muestra son los siguientes:
| Team | Goals |
|------------ |------- |
| Manchester | 26 |
| Liverpool | 25 |
| Man City | 30 |
| Chelsea | 32 |
| Arsenal | 11 |
| West Ham | 22 |
| Stoke | 23 |
Y aquí está el código que estoy usando para crear un diagrama de barras.
g<- ggplot(data = scores) +
geom_bar(mapping = aes(x=Team, y=Goals, color = Team, fill = Team),
stat = "identity")
g <- g + ggtitle("Goals per Team") + ylab("Number of Goals")
g <- g + theme_bw() + theme(legend.position="none") + theme(plot.title = element_text(hjust = 0.5))
g + geom_text(aes(y=Goals, label=Goals))
g
Incluso cuando agregox = Team
eng + geom_text(aes(x = Team, y=Goals, label=Goals))
, todavía me da el mismo error.
¿Qué estoy haciendo mal aquí?