Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Colour the edges and not the nodes in the network #9

Open
DrMattG opened this issue Feb 17, 2021 · 9 comments
Open

Colour the edges and not the nodes in the network #9

DrMattG opened this issue Feb 17, 2021 · 9 comments
Assignees
Labels
enhancement New feature or request

Comments

@DrMattG
Copy link
Collaborator

DrMattG commented Feb 17, 2021

https://twitter.com/aarontay/status/1361958669655531522?s=20

@DrMattG DrMattG added the enhancement New feature or request label Feb 17, 2021
@DrMattG DrMattG self-assigned this Feb 17, 2021
@DrMattG
Copy link
Collaborator Author

DrMattG commented Feb 17, 2021

......linkColour = edges_col) # edge colors

@nealhaddaway
Copy link
Owner

Can we keep the node colour, but somehow highlight input nodes (diff symbol/emphasis/...)?

@DrMattG
Copy link
Collaborator Author

DrMattG commented Feb 18, 2021

@nealhaddaway I have got this code running but I cant work out how to get the input_ids from the data in the shiny

`
library(networkD3)
library(tidyverse)
library(here)
network <- readRDS(paste0(here(),"/inst/shiny-examples/citationchaser/network.RDS"))
head(network)
input_ids=c("050-168-647-208-295", "109-839-221-635-410") # This needs to come from the data
tmp1<-data.frame("IDs"=network$input_lensID, "Group"= network$type)
tmp2<-data.frame("IDs"=network$reference_lensID, "Group"= network$type)
tmp=rbind(tmp1,tmp2)
Nodes=unique(tmp)
Nodes=Nodes %>%
mutate(Group2=ifelse(IDs%in%input_ids, 0, Group)) %>%
mutate(Group2=as.character(Group2)) %>%
mutate(Group2=dplyr::recode(Group2, "0"="input", "1"="reference", "2"="citation"))

make a links data frame using the indexes (0-based) of nodes in 'nodes'

 links <- data.frame(source = match(network$input_lensID, Nodes$IDs) - 1,
                target = match(network$reference_lensID,Nodes$IDs) - 1)
 links<-links %>% 

drop_na()

n_net<-forceNetwork(Links = links, Nodes = Nodes, Source = "source",
                    Target = "target", NodeID ="IDs", Group="Group2", 
                linkColour = "black", opacity = 1, opacityNoHover = 1, zoom=TRUE, legend=TRUE,colourScale = JS('d3.scaleOrdinal().range(["black", "#a50026","#4575b4"]);'))

n_net

`

@nealhaddaway
Copy link
Owner

Woot! It should be:
input$article_ids

@DrMattG
Copy link
Collaborator Author

DrMattG commented Feb 18, 2021

Great I shall give that a go! Also for the hyperlink to the article can we use the lensID pasted at the end of a url or do they use another method? I can get all the nodes to link to my website....(not very useful I know!)

@nealhaddaway
Copy link
Owner

You can paste0() it into the URL below - this should work:

link <- paste0('https://www.lens.org/lens/search/scholar/list?q=lens_id:', lens_id, '&p=0&n=10&s=_score&d=%2B&f=false&e=false&l=en&authorField=author&dateFilterField=publishedYear&orderBy=%2B_score&presentation=false&stemmed=true&useAuthorId=false')

@DrMattG
Copy link
Collaborator Author

DrMattG commented Feb 18, 2021

@nealhaddaway Cool we have links!!!!!!!!!!!!!!!!!!!!!!! Woohoo!!!
Minor problem is that input$article_ids gives me doi and not the lens_id. Where does that conversion happen?

@DrMattG
Copy link
Collaborator Author

DrMattG commented Feb 18, 2021

@nealhaddaway Cool we have links!!!!!!!!!!!!!!!!!!!!!!! Woohoo!!!
Minor problem is that input$article_ids gives me doi and not the lens_id. Where does that conversion happen?

Don't worry - turns out I am an idiot. Have a play with my new branch - I will push it up now and do pull request (maybe useful to wait to merge to see if this is working as expected for a bigger dataset).

@DrMattG
Copy link
Collaborator Author

DrMattG commented Feb 18, 2021

#11 Add links to nodes solves this issue (hopefully)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants