Closed shangguandong1996 closed 4 years ago
I think sparkline supports passing in any of the options from https://omnipotent.net/jquery.sparkline/#common to sparkline()
, like chartRangeMin
and chartRangeMax
.
So for example, you can set a y-axis min and max like this:
sparkline(chickwts$weight[1:10], chartRangeMin = 0, chartRangeMax = 250, width = 300, height = 70)
I think sparkline supports passing in any of the options from https://omnipotent.net/jquery.sparkline/#common to
sparkline()
, likechartRangeMin
andchartRangeMax
.So for example, you can set a y-axis min and max like this:
sparkline(chickwts$weight[1:10], chartRangeMin = 0, chartRangeMax = 250, width = 300, height = 70)
cool! I will try it.
I indeed set the range from the chartRangeMax = 250, width = 300
.
But I failed to set the range accodring to its own cell range using this code.
Am I misundering the function……
reactable(data, columns = list(
weight = colDef(cell = function(values) {
sparkline(values, type = "bar",chartRangeMin = min(values), chartRangeMax = max(values))
}),
boxplot = colDef(cell = function(value, index) {
sparkline(data$weight[[index]], type = "box")
}),
sparkline = colDef(cell = function(value, index) {
sparkline(data$weight[[index]])
})
))
I think you're using chartRangeMin
and chartRangeMax
right, but are you trying to set the same y-min and y-max for each bar chart in the column? If so, you'll need the min and max of the entire column, rather than just the single cell.
In this example, it would be the min and max of the chickwts
weights:
reactable(data, columns = list(
weight = colDef(cell = function(values) {
sparkline(values, type = "bar", chartRangeMin = min(chickwts$weight), chartRangeMax = max(chickwts$weight))
}),
boxplot = colDef(cell = function(value, index) {
sparkline(data$weight[[index]], type = "box")
}),
sparkline = colDef(cell = function(value, index) {
sparkline(data$weight[[index]], chartRangeMin = min(chickwts$weight), chartRangeMax = max(chickwts$weight))
})
))
Let me know if this is different from what you're trying to achieve.
Thanks for your reply!
Actually, chartRangeMin = min(chickwts$weight)
is indeed what I want. I am sorry I make a wrong issue. Thanks for your finally plot a right solution :)
Best wishes.
just like the example code
And I noticed the plot y-axis range is according to the data column min and max. So I am wondering whether can set its own range just like ggplot2 facet
Best wisher And Thanks for this awesome package.
Guandong Shang