jbkunst / highcharter

R wrapper for highcharts
http://jkunst.com/highcharter/
Other
720 stars 149 forks source link

hc_xAxis(categories = labels) doesn't work with all labels #153

Closed diegocgaona closed 8 years ago

diegocgaona commented 8 years ago

Hi,

I'm trying to put labels on my hchart graph, but the hc_xAxis(categories = names(adw_adg_summar[,2:9])) is not working. I see only the first name of the column, and not all column names.

My data is:

Month Impressions Clicks CTR CPC Position Cost Conversions Conv.rate Cost_conv
2016-07-01 1385 161 11.6 0.2 1.7 36.3 3.33 2.1 10.9

My result is:

image

My code:

highchart() %>% 
  hc_legend(enabled = TRUE) %>% 
  hc_xAxis(categories = names(adw_adg_summar[,2:9])) %>% 
  hc_yAxis_multiples (
    list(
      title = list(text = "%, posição e custos"),
      align = "right",
      showFirstLabel = FALSE,
      showLastLabel = FALSE,
      opposite = TRUE
    ),
    list(
      title = list(text = "Impressões, cliques e outros"),
      align = "left",
      showFirstLabel = FALSE,
      showLastLabel = FALSE
    )
  ) %>% 
  hc_add_series(name = "Impressions", type = "column",
                data = adw_adg_summar$Impressions, yAxis = 1) %>% 
  hc_add_series(name = "Clicks", type = "column",
                data = adw_adg_summar$Clicks, yAxis = 1) %>% 
  hc_add_series(name = "CTR", type = "column",
                data = adw_adg_summar$CTR) %>%
  hc_add_series(name = "CPC", type = "column",
                data = adw_adg_summar$CPC) %>% 
  hc_add_series(name = "Position", type = "column",
                data = adw_adg_summar$Position) %>% 
  hc_add_series(name = "Cost", type = "column",
                data = adw_adg_summar$Cost, yAxis = 1) %>% 
  hc_add_series(name = "Conversions", type = "column",
                data = adw_adg_summar$Conversions) %>% 
  hc_add_series(name = "Conversion Rate", type = "column",
                data = adw_adg_summar$Conv.rate) %>% 
  hc_add_series(name = "Conversion Cost", type = "column",
                data = adw_adg_summar$Cost_conv)

I'm using the highCharter 0.4.0.9999

I'm doing something wrong?

Thanks

jbkunst commented 8 years ago

Hi! Can you put dput(adw_adg_summar) please? :)

I think you want:

highcharter() %>%
  hc_add_series(data = adw_adg_summar[,2:9],  colorByPoint = TRUE) %>%
  hc_xAxis(categories = names(adw_adg_summar[,2:9]))

You're adding all the values as separates series, so every value is 0-index in the first category names(adw_adg_summar[,2:9])[1]. Hope it helps, tell me if this ok.

jbkunst commented 8 years ago

But all the values will be in the same axis. If you send me the data we can do what you want but the code will be not so simple/short ;).

diegocgaona commented 8 years ago

Hi @jbkunst,

First, thanks for your quick help.

Yeah, the problem in this case is the second axis, I need it, I want to show this data in one graph only, but the data for some bars are very different.

My data is really that on the issue (the first column can be ignored, the others are numeric), is only a summary from a Google Adwords Campaign. If you want in some specific format for the data, I send to you.

jbkunst commented 8 years ago

Hi @diegocgaona ,

I made some tries but didt work. I think the issue is combine column with two axis. In the scatter/line type the data show where I want, but when I change the type to column the axis is a little out of place.

Check here http://rpubs.com/jbkunst/highcharter-issue-153

diegocgaona commented 8 years ago

Hi @jbkunst ,

Many thanks! I would never thought to make this way.

Worked fine, I liked very much the option 2 for my desires, this way I can select to show one or another type of data, and only one y axis shows.

One off topic question, can I put a suffix or prefix by series? Like this: http://api.highcharts.com/highcharts#series.tooltip.valueSuffix

Thanks very much!

jbkunst commented 8 years ago

Yes, you can :D http://jsfiddle.net/aXvcw/. Not so clean, but it's possible.