Skip to content

How to give points of scatter plot different symbols? #371

Closed

Description

@rdatasculptor

I am trying to give some points in a scatter plot different symbols than others. One way to achieve that, I would expect, is by using e_add("symbol", symbol), like this:

library(echarts4r)
library(echarts4r.assets)
df1 <- mtcars %>% slice(1:16) %>% mutate(symbol=ea_icons("trash"))
df2 <- mtcars %>% slice(17:32) %>% mutate(symbol=ea_icons("user"))
df %>% 
  e_charts(mpg) %>% 
  e_scatter(
    wt, 
    qsec,
    name = "Trash"
  ) %>%  
  e_add("symbol", symbol) %>%
  e_legend(icons = ea_icons("trash"))

As you can see the plot seems empty. Is this a bug or should it be done in another way?
(I borrowed the example from here)

Many thanks in advance!

Activity

  1. JohnCoene commented on Sep 13, 2021

    @JohnCoene
    Owner

    That is because the function e_add is to nest data. Your issue made me rethink how this works though.

    I deprecate e_add in favour of:

    • e_add_nested
    • e_add_unnested

    More info with ?nesting see "Functions" section.

    library(dplyr)
    library(echarts4r)
    library(echarts4r.assets)
    
    # serialise ea_icons
    add_icon <- function(symbols){
      sapply(symbols, ea_icons)
    }
    
    mtcars %>% 
      mutate(
        symbol = sample(c("trash", "user"), n(), replace = TRUE), # random icon
        symbol = add_icon(symbol)
      ) %>% 
      e_charts(mpg) %>% 
      e_scatter(
        wt, 
        qsec
      ) %>%  
      e_add_unnested("symbol", symbol) %>%
      e_legend(icons = ea_icons("trash"))
  2. self-assigned this
    on Sep 13, 2021
  3. rdatasculptor commented on Sep 13, 2021

    @rdatasculptor
    ContributorAuthor

    You made my day! Your changes in the nesting.R code works!

    I guess we can close this issue now?

  4. JohnCoene commented on Sep 13, 2021

    @JohnCoene
    Owner

    Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

featureNew featurefeedbackWaiting for feedback

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions