Closed dpprdan closed 7 years ago
Hi @dpprdan
Indeed, hchart
and highchart
are differents functions and then they have different motivations/behaviors.
hchart
is for make quick charts given minimal information from the user. For example hchart(ggplot2::economics, "line", hcaes(date, pop))
recognize datetime class (and internally add hc_xAxis(type = "datetime")
, etc.
highchart
allow you have more control from the output.About the theme: I'm agree with this can look like a bug. The issue is that hchart
disable the makers (due is a line chart [and not a line-plot chart]) via plotOptions
and this have priority over the theme. I know this is really subjetive, just I think it was a good default (not the perfect, but a good one)
You can force the markers using hc_plotOptions
:
hc_hchart <- citytemp %>%
select(-new_york,-london) %>%
gather(city, temp, tokyo, berlin) %>%
hchart("line",
hcaes(x = int, y = temp, group = city)
)
thm <- hc_theme(
chart = list(backgroundColor = "#eeeeee"),
plotOptions = list(
series = list(
marker = list(enabled = TRUE)
)
)
)
hc_hchart %>%
hc_add_theme(thm) %>%
hc_plotOptions(
series = list(
marker = list(enabled = TRUE)
)
)
Finally I think a good approach would be use highchart
to have more control in what are you trying to do.
Regards,
Thanks @jbkunst! I was aware of the differences between hchart
and highchart
as well as hc_plotOptions()
(actually I am using marker = list(enabled = TRUE)
within hchart()
as a work-around - "work-around" again being a matter of perspective, I guess, though not really IMHO).
Your design choices are your prerogative of course. That being said, my perspective on this is the following: No markers as a default is not a bad choice, but for consistency it should be the same (or at least be transparent) across both plotting functions. The real problem is, however, that essentially hm_add_theme()
works differently (or not at all with regard to the markers and hchart
for example) depending on the function that created the hc
object. And that can get messy.
How about making the default theme more transparent, i.e. separate content from visualisation more, and make it possible to override it? I am pretty new to highcharts and highcharter
, but as far as I can tell there is no explicit default theme at the moment? But at least implicitly you must be using some defaults (e.g. no markers with hchart
). So it might be a good idea to explicitly add this as a default theme, which could then be called from within hchart()
and highchart()
?
Another way to look at the problem (and a bit puzzling to me), is that plotOptions
in hchart()
cannot be overridden, because overriding a theme seems to work fine in general? E.g. hc %>% hc_add_theme(hc_theme_google()) %>% hc_add_theme(hc_theme_ffx())
Thanks to you @dpprdan
I think you're right, It's better maintain the highcharts defautls. So I will delete the part wich set the markers to false in the line chart as you mention in the last part.
Thanks @jbkunst! Maybe you can give my idea regarding a default theme another thought as well?
Unfortunately I think I found a similar issue, though this time not directly theme-related: Please compare:
hchart(df_area, "area",
hcaes(x = year, y = pop, group = continent)) %>%
hc_plotOptions(area = list(marker = list(enabled = FALSE)))
to
highchart() %>%
hc_add_series(df_area, "area",
hcaes(x = year, y = pop, group = continent)) %>%
hc_plotOptions(area = list(marker = list(enabled = FALSE)))
Apparently it is not possible to disable markers with hc_plotOptions
on a hchart
object. I suppose this problem is also related to the default options set in hchart
?
Hi @dpprdan,
I removed the hc_plotOptions in the hchart
so the next code give the same results (hchart put labels in the axis):
highchart() %>%
hc_xAxis(categories = citytemp$int) %>%
hc_add_series(name = "Berlin", data = citytemp$berlin) %>%
hc_add_series(name = "Tokyo", data = citytemp$tokyo)
highchart() %>%
hc_xAxis(categories = citytemp$int) %>%
hc_add_series(citytemp2, "line", hcaes(x = int, y = temp, group = city))
hchart(citytemp2, "line", hcaes(x = int, y = temp, group = city))
I don't have the df_area
, can you check if this work for that data frame too? If you can't test, can you give me some dput
to make some tests?
I tried to install highcharter from github with devtools::install_github("jbkunst/highcharter")
. library("highcharter")
gives the following error:
Error in FUN(X[[i]], ...) :
lazy-load database 'C:/Users/daniel/Documents/R/win-library/3.4/highcharter/data/Rdata.rdb' is corrupt
In addition: Warning messages:
1: In FUN(X[[i]], ...) : restarting interrupted promise evaluation
2: In FUN(X[[i]], ...) : internal error -3 in R_decompress1
So I cannot test at the moment.
df_area
is the data from the Replicating Highcharts Demos vignette:
year <- seq.int(from = 1750, to = 2050, by = 50)
Asia <- c(502, 635, 809, 947, 1402, 3634, 5268)
Africa <- c(106, 107, 111, 133, 221, 767, 1766)
Europe <- c(163, 203, 276, 408, 547, 729, 628)
America <- c(18, 31, 54, 156, 339, 818, 1201)
Oceania <- c(2, 2, 2, 6, 13, 30, 46)
df_area <- data.frame(year,Asia,Africa,Europe,America,Oceania) %>% gather(continent, pop, -year)
@dpprdan
That's weird, Not sure what could it be. I run the devtools::install_github
without problems. Not sure if you have the same result with source("https://install-github.me/jbkunst/highcharter")
(## highcharter * 0.5.0.9999 2017-04-28 Github (jbkunst/highcharter@22f0d5b)
in
http://rpubs.com/jbkunst/highcharter-issue-302)
Sorry, my fault. I had highcharter loaded in another R session, that's why the update failed.
The df_area chart works fine with regard to the markers (note that my chart example as such does not make a lot of sense, because it is not stacked - so it really is a minimal working example).
For the line charts the markers and themes work nicely. However, the two graphs differ with respect to the axis labels (which is as expected and fine) but also with respect to the x-axis tick marks (between the integer labels with highchart()
, on the labels with hchart()
. Do you set a default in the hchart() object for the tick marks as well? I don't have time now to figure out what setting exactly determines this (and would appreciate if you could tell me) but I remember having some problems with setting tick marks a few days back. So maybe we have the same problem as with the markers in the area plot, i.e. that it's not possible to override your default?
See the updated version of http://rpubs.com/jbkunst/271521. Compare:
highchart() %>%
hc_xAxis(categories = citytemp$int) %>%
hc_add_series(citytemp2, "line", hcaes(x = int, y = temp, group = city))
with
highchart() %>%
hc_xAxis(categories = citytemp$int) %>%
hc_add_series(citytemp2, "line", hcaes(x = as.character(int), y = temp, group = city))
The effect is that int
is continous, and the javascript is 0-based.
hc_add_series.vector
(hc_add_series(name = "Berlin", data = citytemp$berlin)
) the data is given to highcharts as [-0.9, 0.6, 3.5, ...]
and highcharts interpret put the fist value in the first value of the category.hc_add_series.data.frame
(hc_add_series(citytemp2, "line", hcaes(x = as.character(int), y = temp, group = city))
) the data is given to highcharts as [{ x: "1" y :-0.9}, {x: "2", y: 0.6}, ]
so is explicit where the point need to be. Thanks for your explanation (and sorry for the delay)!
However, I don't think that hc_add_series.vector
vs. hc_add_series.data.frame
nor the fact whether x
is an integer or character vector is the issue here per se, but rather how hchart()
handles integers differently than highchart()
with respect to the x-axis markers.
The following all create the same chart:
# Dataframe with x as integer
highchart() %>%
hc_xAxis(categories = citytemp$int) %>%
hc_add_series(citytemp2, "line", hcaes(x = int, y = temp, group = city))
# Dataframe with x as character
highchart() %>%
hc_xAxis(categories = citytemp$int) %>%
hc_add_series(citytemp2, "line", hcaes(x = as.character(int), y = temp, group = city))
# Vector with x as integer
highchart() %>%
hc_xAxis(categories = citytemp$int) %>%
hc_add_series(name = "berlin", data = citytemp$berlin) %>%
hc_add_series(name = "tokyo", data = citytemp$tokyo)
# hchart with x as character
hchart(citytemp2, "line", hcaes(x = as.character(int), y = temp, group = city))
The only different chart is this
# hchart with x as integer
hchart(citytemp2, "line", hcaes(x = int, y = temp, group = city))
See http://rpubs.com/dpprdan/273485 for a bit more elaboration.
Hi @dpprdan ,
Soory for the delay!
I posted some rpubs to show why the result in every chart http://rpubs.com/jbkunst/301558 , tell me if this is clearer.
I will close the issue but you/we can reopen if is needed ;)! Thanks.
hchart()
andhighchart()
seem to have different default chart layouts. This is a problem if one wants to combine different graphs with both methods on one page and also introduces a bug in the handling of themes inhchart
(see below).To illustrate, let's start with a simple
highchart()
example:The resulting graph on my system:
Now this should give the same chart with hchart() (yes, the resulting objects differ, but the graph layout should still be the same, IMHO):
Notice the missing markers and the different tickmarks on the x-axis. Also the number of tick-labels on the x-axis are reduced (and this is not due to the sightly reduced space due to the y-axis label).
In addition, it is not possible to add the markers via a theme to the
hchart()
object.Notice the grey background, but missing markers.
Now let's see whether the code works with the
highchart()
object. (I disable the markers in the theme now, since they are enabled by default).