Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BoundaryGap #14

Closed
motassimbakali opened this issue Jun 10, 2018 · 4 comments
Closed

BoundaryGap #14

motassimbakali opened this issue Jun 10, 2018 · 4 comments

Comments

@motassimbakali
Copy link

First of all, many thanks for this amazing package!

When creating a line chart, I came across the fact that there is always a gap between the start/end of the line-chart and the x-axis. I found out through Baidu that you can change this by setting boundaryGap to FALSE.

However, I could not get this to work. I tried the following:
mtcars %>% e_charts(wt) %>% e_area(qsec) %>% e_x_axis(boundaryGap = FALSE, min = 1)

Is this not available in the package or did I do something wrong? Thank you!

@JohnCoene
Copy link
Owner

I cannot reproduce the issue.

Say we plot something clearer first.

df <- data.frame(
  x = 1:10,
  y = 1:10
)
df %>% 
  e_charts(x) %>% 
  e_line(y) %>% 
  e_tooltip(
    trigger = "axis"
  )

You shouldn't see any boundary gap. Now say we plot your example again, but with tighter boundaries to our graph.

min <- min(mtcars$wt)
max <- max(mtcars$wt)

mtcars %>% 
  e_charts(wt) %>% 
  e_area(qsec) %>% 
  e_x_axis(
    min = min,
    max = max
  ) %>% 
  e_tooltip(trigger = "axis")

The documentation for boundaryGap actually states that the parameter works differently for numerical and categorical data:

  • For numerical continuous data pass a vector
  • For categorical data pass TRUE or FALSE
mtcars %>% 
  e_charts(wt) %>% 
  e_area(qsec) %>% 
  e_x_axis(
    boundaryGap = c("50%", "50%") # add boundary gap
  ) %>% 
  e_tooltip(trigger = "axis")

If you have categorical:

df <- data.frame(
  x = LETTERS[1:4],
  y = runif(4, 1, 3)
)

df %>% 
  e_chart(x) %>% 
  e_bar(y) %>% 
  e_x_axis(
    boundaryGap = FALSE 
  )

So generally speaking you want to use boundaryGap depending on the data you have and the plot you are trying to create.

Let me know if this helps.

@motassimbakali
Copy link
Author

Thank you very much for your quick reply! All seems to work very well and I can use the tool_tip as well when using "axis".

However, if I change the e_tooltip to "item" instead of "axis", I do not get the tooltip for the maximum x-value. So for your first example:

df <- data.frame(
  x = 1:10,
  y = 1:10
)
df %>% 
  e_charts(x) %>% 
  e_line(y) %>% 
  e_tooltip(
    trigger = "item"
  )

This doesn't give me a tooltip at x = 10. Do you know what the reason is behind this?

@JohnCoene
Copy link
Owner

Indeed.

Well this is when you could, for instance, use boundaryGap.

# initialise chart
df <- data.frame(
    x = 1:10,
    y = 1:10
)
df %>% 
    e_charts(x) %>% 
    e_line(y) %>% 
    e_tooltip(
        trigger = "item"
    ) %>% 
    e_tooltip(trigger = "item") -> p

Using boundaryGap - a vector for continuous data, as mentioned above.

p %>% e_x_axis(boundaryGap = c(0, .1))

Or min and max

p %>% e_x_axis(min = 0, max = 12)

And there are probably other ways I'm unaware of.

@motassimbakali
Copy link
Author

Thank you very much! I will use that way and close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants