Comments (12)
Thanks, seems to work just fine for the toy example:
And if you want to have "nice" ticks, using tickAmount
works:
df <- data.frame(x=c(1, 2, 3), y=c(0, 1, 0))
apex(data=df, mapping=aes(x=x, y=y), type="line") %>%
ax_xaxis(type="numeric", tickAmount=2)
Only tickAmount='dataPoints'
doesn't work as advertises on the Apex help:
If you have a numeric xaxis xaxis.type = 'numeric', you can specify tickAmount: 'dataPoints' which would make the number of ticks equal to the number of dataPoints in the chart.
But I don't have a use case for it.
from apexcharter.
...and the initial example now also shows correct x-axis labels:
x <- seq(-0.3, 0.3, 0.01)
df <- data.frame(x=x, y=dnorm(x, mean=0, sd=0.1))
apex(data=df, aes(x,y), type='line') %>%
ax_xaxis(type='numeric',
max=0.3,
range=0.6,
tickAmount=6,
labels=list(formatter=format_num(".2f"))
)
from apexcharter.
There is still a small issue, though, if one wants to set a custom x-axis range: It has to do with the precision of the tick labels. Out of the box, the plot is pretty confusing:
x <- seq(-4, 4, 0.01)
df <- data.frame(x=x, y=dnorm(x))
apex(data=df, aes(x,y), type='line') %>%
ax_xaxis(type='numeric',
max=5,
range=10,
tickAmount=8
#labels=list(formatter=format_num(".2f"))
)
One needs to specify the formatting of the tick labels to get a meaningful x-axis:
x <- seq(-4, 4, 0.01)
df <- data.frame(x=x, y=dnorm(x))
apex(data=df, aes(x,y), type='line') %>%
ax_xaxis(type='numeric',
max=5,
range=10,
tickAmount=8,
labels=list(formatter=format_num(".2f"))
)
I.e., the -1.25 is rounded and displayed as -1, and the -2.50 is rounded and displayed as -3 in the first chart. However, if you set tickAmount=10
to begin with, everything is fine. So, overall, this is a limitation of the Apex library, not the r implementation.
from apexcharter.
Seems like a bug with float, it doesn't occur if we use x*100
or without tickAmount
option.
I'll open an issue in Apexcharts.js repo.
Victor
from apexcharter.
Great, thanks. Here is a minimal reproducible example to reproduce the bug with type="numeric"
, where the x-axis labels are off (the x-value in the hover information is correct, though):
df <- data.frame(x=c(1, 2, 3), y=c(0, 1, 0))
apex(data=df, mapping=aes(x=x, y=y), type="line") %>%
ax_xaxis(type="numeric")
from apexcharter.
I tried in a codepen that had version 3.4.1 of apexchart, and it did give the expected result:
from apexcharter.
Thanks,
Here you used categories
to set x values, in apex
I use numeric paired values:
"data": [
{
"x": 1,
"y": 0
},
{
"x": 2,
"y": 1
},
{
"x": 3,
"y": 0
}
]
The bug here seems to appear if option tickAmount
is not set.
https://codepen.io/pvictor-r/pen/abBLyBX
from apexcharter.
Sorry if this is not the right lead (I understand very little about these things), but when you change to version 3.4.1 in your codepen (at least this is what I think I'm doing in settings), the graph does render correctly, i.e., the bug goes away. I don't know how easy it is to update to this version.
from apexcharter.
3.4.1 is actually an old version (17 Feb 2019)
Last version released is 3.23.1, and is the one used in {apexcharter} GitHub (CRAN use 3.22.2)
from apexcharter.
I believe the issue was fixed on Apex's gihub a few weeks ago. Any chance this will be rolled over soon, so that code like this gives correct results:
df <- data.frame(x=c(1, 2, 3), y=c(0, 1, 0))
apex(data=df, mapping=aes(x=x, y=y), type="line") %>%
ax_xaxis(type="numeric")
Many thanks!
Bernhard
from apexcharter.
Yes I openned an issue (apexcharts/apexcharts.js#2249) ;)
I was waiting for an official release, however I build manually the JS bundle from Apexcharts repo so you can try.
You may experience some bugs ^^, let me know.
Victor
from apexcharter.
Thanks for the tests!
ApexCharts 3.26.0 has been released and included in apexcharter.
I will push to CRAN soon.
from apexcharter.
Related Issues (20)
- Adding Icons or Color to the Tooltip HOT 2
- Adding Confidence Intervals HOT 4
- Creating box plot with apexcharter HOT 2
- facet not working on shinyapps HOT 3
- Brush does not work HOT 3
- Combining facets with annotations HOT 1
- Mixed/Combo charts when using apex() function to create series
- Stacked Bar Chart by Week Ending Date - x-axis labels HOT 3
- Colour mis-match on line markers for more than 10 series HOT 1
- No shared tooltip HOT 4
- Thrid y axis HOT 2
- Change to new cran checks badge URL HOT 1
- Feature request: New chart type - box plots HOT 5
- Adding Icons to the Labels in a Legend HOT 4
- Format numbers in spark_box's tooltip HOT 2
- ax_forecast_data_points() seems to be missing HOT 2
- Remove Time Gaps from Candlestick Chart HOT 2
- [Feature request] - adding outliers and custom data points to a boxplot
- Synchronize Charts Example doesn't display both plots at the same time in Rstudio's plot panel. HOT 2
- Feature request: bring crosstalk functionality to connect apexchart with tables
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from apexcharter.