Area and Line Graph in R with x-axis as String

2

I would like to make an area chart and insert another superimposed line chart. I am not able to accomplish this, because the graph of x that I want to put are strings and everything is wrong. The figure should look like the chart below that I did in excel. As I will have to do several in a loop, I wanted to automate. I tried to use ggplot2 and plotly, but to no avail. The dataset can be purchased through the link: link

    
asked by anonymous 07.02.2017 / 17:59

1 answer

4

I think the code below will solve your problem.

library(ggplot2)

dados <- read.table(file="resposta.csv", header=T, sep=";")

ggplot(dados, aes(x=X, y=custo_med_gerFV_c_financ)) + 
  theme_bw() +
  geom_area(colour="blue", fill="blue") + 
  geom_line(aes(x=X, y=custo_med_rede), colour="darkorange", size=1.5) +
  theme(axis.text.x=element_text(angle=90, hjust=1, vjust=0.5)) +
  scale_x_continuous(breaks=dados$X, labels=levels(dados$Disco)) + 
  labs(x="Concessionárias", y="Custo")

    
08.02.2017 / 12:33