JohnCoene / echarts4r

🐳 ECharts 5 for R
http://echarts4r.john-coene.com/
Other
585 stars 82 forks source link

e_gauge: remove plot area margins #568

Open micboat opened 10 months ago

micboat commented 10 months ago

Hi is there any way to completely remove or at least reduce the margins from e_gauge plots? the space between the gauage plots and the rest of the narrative in my quarto document is too noticeable.

I tried setting e_grid but it doesnt seem to apply.

e_charts() %>% e_y_axis(gridIndex = 0, min=0,max=100) %>% e_gauge(1.01, "LoA", min = 0, max = 2, splitNumber = 20, axisLine = list( lineStyle = list( color = list( c(0.4, "red"), c(0.45, "yellow"), c(0.55, "green"), c(0.6, "yellow"), c(20/20, "red") ) ) ))

Am trying to set up 6 gauges (2 rows 3 cols) compacted but the margins makes that impossible. I tried the e_arrange but it didnt help either Screenshot 2023-09-09 at 9 15 15 PM

rdatasculptor commented 10 months ago

@micboat can you add what you tried with e_grid modifications? Thanks!

micboat commented 10 months ago

@rdatasculptor I tested your approach. Couldn't get the labels on there so I ended up creating each gauge and using combinewidgets to display them. Each chart had different metrics customization. But this is how far I got with your recommendation:

Load the library

librarian::shelf(echarty, data.table)

df <- data.table( Metric = c('LoA', 'CoD', 'PRB', 'PRD', 'MKI', 'RRI'), Estimate = c(1.003, 9.14, -0.041, 1.012, 0.881, 0.065), Min = c(0, 0, -0.5, 0.5, 0.5, 0), Max = c(2, 25, 0.5, 1.5, 1.5, 1), Split_no = c(10, 10, 10, 10, 10, 10), Colorlist = list( list( c(0.4, "red"), c(0.45, "yellow"), c(0.55, "green"), c(0.6, "yellow"), c(1, "red") ), list( c(4/25, "red"), c(5/25, "yellow"), c(10/25, "green"), c(12/25, "yellow"), c(25/25, "red") ), list( c(8/20, "red"), c(9/20, "yellow"), c(11/20, "green"), c(12/20, "yellow"), c(20/20, "red") ), list( c(8/20, "red"), c(9/20, "yellow"), c(11/20, "green"), c(12/20, "yellow"), c(20/20, "red") ), list( c(8/20, "red"), c(9/20, "yellow"), c(11/20, "green"), c(12/20, "yellow"), c(20/20, "red") ), list( c(0.10, "#006400"), c(0.25, "#7fbf7f"), c(0.50, "#FFFF00"), c(0.75, "#FFA07A"), c(10/10, "red") ) ) )

tmp <- lapply(ec.data(df, 'names'), function(c) { # ec.data() converts data.frame into named list ec.init(height= '40vh', grid= list(left=0, right=0, top=0, bottom=0, show=T), series= list(list(type= 'gauge', data= list(c$Estimate), label=c$Metric, radius='95%', min= c$Min, max= c$Max, splitNumber= c$Split_no, axisLine= list( lineStyle= list( color= c$Colorlist ) ) )) ) }) ec.util(cmd= 'layout', charts= tmp, cols= 3)

rdatasculptor commented 9 months ago

Thanks! I think you put the wrong script in your answer. That's {echarty}, not {echarts4r} :).