JohnCoene / echarts4r

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

Formatter with ec.clmn #604

Closed MrMisc closed 6 months ago

MrMisc commented 6 months ago

Given the following example, could someone guide me through how to call the respective variables inside the dataset for the formatter? example.csv is the dataset used here.

big<-read.csv("example.csv")
big %>% mutate(Percent = Total_Divorces/`Aggregate Marriages`*100) %>%
  group_by(Seed) %>% arrange(Year) |> e_charts(Year)|>
  e_area(Percent,`Total Marriages`,lineStyle = list(width = 0.5,opacity = 0.4))|>
  e_x_axis(max = YY_,min = 1980,nameLocation = 'center',nameTextStyle = list(fontWeight = 'bolder',padding = 8))|>
  e_y_axis(nameLocation = 'center',nameTextStyle = list(fontWeight = 'bold',padding = 28))|>
  e_legend(z = 5,right = 2,top = 40,bottom = 60,width = 50,selector = "inverse",
           show=TRUE,icon = 'circle',emphasis = 
             list(focus = "series",selectorLabel = list(offset = list(10,0))), 
           align = 'right',type = "scroll",width = 10,orient = "vertical")|>
  e_datazoom(type = "slider",orient = "horizontal",top = 5,right = 150,width = 500)|>
  e_axis_labels(x = "Year",y = "Percentage of Marriages that ended in divorce")|>
  e_tooltip(formatter = ec.clmn('For marriages that commenced <br> in the year <b>%@</b>,by <br> Year <b>%@</b>,<b> %@% </b> <br> of marriages have terminated',8,1,2)
            ,trigger = "item")|>e_theme("tech-blue")

As of right now, this plot manages to show all the variables except the first one, coming out as undefined. I want to call the 'Seed' column from the dataset, but I do not understand how to call it really. The second and third variable I call inside the formatter are 'Year' and 'Percent', which appear to correspond to clmn 1 and 2 for some reason.

> names(big %>% mutate(Percent = Total_Divorces/`Aggregate Marriages`*100) %>%
+           group_by(Seed))
[1] "Seed"                "Year"                "Total_Divorces"      "Total Marriages"    
[5] "Aggregate Marriages" "Category"            "Amount"              "Percent"  
rdatasculptor commented 6 months ago

ec.clmn is from the echarty package? Then it is better to ask your question in that github I think