Comments (6)
Try changing this line
geom_nodes(aes(colour = color), size = 3, vertex.label<- V(net)$Subject)
to
geom_nodes(aes(colour = subject))
It's ok that the graph changes a bit every time you plot it; the positions of the nodes are not completely determined by the graph structure and the layout type, and so there's a bit of randomness. If you want to get rid of that, you can type set.seed(0)
before running the plotting command and that should give you a consistent orientation.
from f1000_workflow.
@jfukuyama Thank you for getting back to me.
The set.seed(0)
worked well thank you. Then I tried changing the geom_nodes
line to the one you suggested but once I did that the graph only showed two dots which had random numbers.
It appears that this part may be important since when I tried to run it without an error was generated:
vertex.label<- V(net)$Subject)
I tried changing it to either:
vertex.label<- V(net)$id)
or
vertex.label<- V(net)$color)
but then I got this error:
Error:
data
must be a data frame, or other object coercible byfortify()
, not an integer vector
I am not sure where to go from there.
from f1000_workflow.
After messing with it some more it appears that the line vertex.label...
does not make a difference. In fact it does not seem to be doing anything. Also I decided to print()
the V(net)$subject
and that gave me this list:
[1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14
So now I realize that the labels that I want in that vertex are not there. I am not sure how to get them into that list though.
from f1000_workflow.
Hey there, sorry for the delayed reply, I've been without the internet for a while.
It's hard to debug this without having access to all of your data, but it looks like what happened with your V(net)$subject
is that a variable that was initially a factor got coerced to an integer (which is how R stores factors internally). That makes the subject IDs go from meaningful to the integers that you get there. Then the plot is faithfully plotting the integers, which are unfortunately the wrong thing.
What you should do is go through all the assignments you used to create V(net)$subject
and see where it switches over from being the good subject labels to being the numbers you see there. (So for instance, it was created with V(net)$subject <- sampledata[names(V(net)), "Subject"]
, so you should check that the sampledata
data frame is good, that it has a column called Subject
, that names(V(net))
match the row names of sampledata
, and so on.)
from f1000_workflow.
No worries and thank you!
I checked sampledata
, names(V(net))
, and then sampledata[names(V(net)), "Subject"]
. Everything was correct until I tried to print V(net)$subject
. When I did that I got all only numbers, which leads me to believe that that is where the problem lies. For some reason that command is not doing what it is supposed to do. Your comment about V(net)$subject got me thinking so I was able to eventually figure it out, which I was very happy about. I decided to print subject
which gave me:
print(subject)
[1] ML04 MLK01 MLK02 MLK03 PP01 PP02 PP03 PP07 PP08 PP12 PP13 PP14
[13] PP15 PP16
14 Levels: ML04 MLK01 MLK02 MLK03 PP01 PP02 PP03 PP07 PP08 PP12 PP13 ... PP16
I realized then that the levels were what I wanted to have the legend equal to. Once I figured that out I looked at my previous code and realized that colrs
was the current input for the legend via V(net)$color
. So then I decided to try setting V(net)$color
equal to the levels. Once I did that I was successful and able to get the correct graph. I also included the code that eventually worked for me.
net <- make_network(ts, max.dist= 1) #was only able to get 4 points until I increased the max.dist. Then I was able to access all of the data.
net
sampledata <- data.frame(sample_data(ts))
V(net)$subject <- sampledata[names(V(net)), "Subject"]
V(net)$id <- levels(subject)
ggplot(net, aes(colour, x = x, y = y, xend = xend, yend = yend), layout = "fruchtermanreingold") +
geom_edges(color = "darkgray") +
geom_nodes(aes(colour = id), size = 3, vertex.label<- V(net)$Subject) +
scale_shape_identity() +
theme(axis.text = element_blank(), axis.title = element_blank(),
legend.key.height = unit(1.5,"line")) +
guides(col = guide_legend(override.aes = list(size = 4)))
set.seed(0)
Thank you again! I couldn't have done it without your help.
from f1000_workflow.
That's great, I'm so glad you figured it out!
from f1000_workflow.
Related Issues (20)
- Is "http://www.mothur.org" currently down? HOT 5
- Problem with phangorn package in the revised workflow HOT 7
- creating and plotting graphs from Workflow for Microbiome data HOT 7
- Component sample names do not match. Try sample_names(). HOT 4
- Effects of prevalence filtering on downstream analysis HOT 2
- Prevalence filtering issue HOT 1
- question about the abundant unidentified ASVs HOT 2
- Quality control of code HOT 6
- NMDS plot for 16s amplicon HOT 5
- Scale bar for tree using phangorn and phyloseq HOT 2
- Error learn question HOT 2
- Issue in Creating Phylogenetic tree HOT 9
- Error in R code HOT 1
- Error in constructing a neighbor-joining tree HOT 1
- Problems with generating a phylogenetic tree HOT 9
- Alignment error
- bootstrap in the tree? HOT 3
- tree format? HOT 3
- Bad alloc... maybe bad alignment? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from f1000_workflow.