0

Thanks for the previous feedback. This is my question edited with all the comments suggested:

I am trying to plot some data in multiple columns: the total performance of industrial activity for years 2015 to 2018, performance of construction for the same years, performance of manufactures for the same years and so on.

I used some geoms and the best I could achive was a graph with the labels but those are one over the other in each category. The labels are not distributed in each column.

This is what I get

The code that I wrote was the following, considering that the main problem could be in the geom_label part:

Ramo <- c("Total", "Total", "Total", "Total", "Minería", "Minería", "Minería", 
          "Minería")

Periodo <- as.character(c(2015, 2016, 2017, 2018, 2015, 2016, 2017, 2018))

Valor <- as.numeric(c(0.6087, -0.1573, -0.4233, -2.5450, -3.7347, -7.7113,
                      -6.6872, -8.3708))

melted <- data.frame(Periodo, Ramo, Valor)

graficaTotal <- ggplot(melted, aes(x = Ramo, y = Valor)) +
  geom_col(aes(fill = Periodo), position = "dodge") +
  geom_label(aes(x = Ramo, y = Valor, 
                        label = paste0(round(melted$Valor, 1), '%')),
                     size = 3) +
  ggtitle("Actividad Industrial: Variación anual diciembre, cifras originales (%)") +
  theme(plot.title = element_text(face = "bold", size = 10, hjust = 0.5)) +
  theme(axis.title.x = element_blank(), axis.title.y = element_blank(), 
        axis.line = element_line(color = "black"), 
        panel.border = element_blank(),  
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(), 
        panel.background = element_blank()) +
  geom_hline(yintercept = 0) +
  scale_y_continuous(limits = c(-10, 5)) +
  theme(legend.position = "bottom") +
  theme(legend.title = element_text(size = 7), 
        legend.text = element_text(size = 7), legend.key.size = unit(0.2, "cm")) +
  scale_fill_manual(name = "", values = c("2015" = "2015", "2016" = "2016", 
                                          "2017" = "2017", "2018" = "2018"))


print(graficaTotal)

In the end this is a picture of the desired outcome: Possible outcome

Thanks in advance for your help.

Pedro
  • 1
  • 2
  • 5
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. We can't run the code without data. Remove anything not essential to the question like theme or color commands to simplify the code. – MrFlick Aug 12 '19 at 20:52
  • Since you're asking an aesthetic question, a figure of what you have at the moment and what you wish to attain would be helpful too. – Adam Quek Aug 13 '19 at 04:17
  • You probably need to specify the position argument within geom_label, but please provide at least what you're getting now and your desired output. – aaumai Aug 13 '19 at 09:37

0 Answers0