I've trying to make a simple line graph using highchart but for some reason, the dates are all in different order.
This is the code I'm using to create the graph:
hchart(dataframe,"line",hcaes(
x=MONTH,
y=VALUE,
group=NAME
))%>%
hc_yAxis(TITLE="VALUE")%>%
hc_xAxis(title="")
})
and this is the output I get:
as you can see, this is completely wrong. I´ve tried to order by the month on the dataframe before creating the graph, as well as adding X=sort(MONTH)
but nothing seems to work. My dataframe looks like this:
|| Name || Month || Value
So I group by Name and Month, and do a simple sum of the total value. The Month value on the dataframe is of type char and comes from an sql query TO_CHAR(DATE,'YYYY-MM')
I´ve tried doing it on dplyr but the output is still the same.
Thanks for the help!
Edit:
Here is a reproductible example for you to try out:
library(highcharter)
new_data <- data.frame(names = c("name1","name2","name3","name4","name5","name6","name7","name8","name9"
,"name2","name3","name4","name5","name6","name7","name8","name9"
,"name2","name3","name4","name5","name6","name7","name8","name9"
,"name2","name3","name4","name5","name6","name7","name8","name9"),
months = c("2019-01","2019-06","2019-07","2019-08","2019-01","2019-02","2019-03","2019-04","2019-05"
,"2019-06","2019-07","2019-08","2019-01","2019-02","2019-03","2019-04","2019-05"
,"2019-06","2019-07","2019-08","2019-01","2019-02","2019-03","2019-04","2019-05"
,"2019-06","2019-07","2019-08","2019-01","2019-02","2019-03","2019-04","2019-05"),
values = c(150,152,1506,1245,5214,2312,2435,241,421
,152,1506,1245,5214,2312,2435,241,421
,152,1506,1245,5214,2312,2435,241,421
,152,1506,1245,5214,2312,2435,241,421))
hchart(new_data,"line",hcaes(
#x=sort(MONTH),
x=months,
y=values,
group=names
))%>%
hc_yAxis(TITLE="values")%>%
hc_xAxis(title="")