When using wildcards to graph metrics is there a way to force an order on the matching metrics? - graphite

I've got two graphs that use the something like the following metrics :
graph1 : oldMethod.latencies_msec.percentiles.p{25,50,75,90,95,99}
graph2 : newMethod.latencies_msec.percentiles.p{25,50,75,90,95,99}
I'd like these two graphs to use the same colors for similar metrics. I don't care much about the colours but would like the two p25s in both graphs to have the same color, the two p50s to have the same color and so on.
If I don't use wildcards and use 6 different data lines for each graph and order the metrics the same way for both graphs, then I get consistent colors but if I use wildcards the ordering of the metrics seems arbitrary.
Is there anyway to fix the ordering? If not any insight into the logic behind the metric ordering would be helpful.

There is a change in works that will solve this problem. Here is the link to it in github - https://github.com/graphite-project/graphite-web/pull/831.
You might have to do sortByName(aliasByNode(your_metrics_here, position)) to get shorter names that can be sorted conveniently for metrics to be rendered in the right order. You have to also make sure you have the same number of nodes in all the graphs to get the desired result.

You can assign a color manually to a metric like so:
&target=color(my.data.here,"blue")
see bgcolor
http://graphite.readthedocs.org/en/1.0/url-api.html#bgcolor
Now to order, you can use something like:
target=limit(sortByMaxima(my.data.here,8)

Related

Pictured link is my coding. How do I make a proper good graph?

Okay so I have an assignment where I need to conduct a graph that best represents the before and after affects of two streams. The graph(s) have to contain means and standard error for each stream in each year.. I cannot figure the proper coding for the graph. I continue to get errors and bad graphs. I will attach a sample of what the data looks like too.
A sample of the data, it changes to after at 51
Try to post a reproducible error or specification of your problem.
As far as I can analyze your problem, you maybe should not create b4, because it does not seem to be an effective subset. If you want to assemble certain plots, you can use plot_grid from cowplot.
Otherwise you can add facet_wrap(~ VARIABLE_NAME) to ggplot in order to create many plots divided by deviating observations in the specified variable.
If you are not happy with the visual outcome and result of your graph, you can choose another theme, e.g. theme_bw() which can be simply added to your ggplot function. You can add and change further labels with labs() and theme().

Change colors in r plot

I am currently trying to plot some data and don't manage to obtain a nice result. I have a set of 51 individuals with each a specific value (Pn) and split within 14 groups. The closest thing I end up with is this kind of plot. I obtain it thanks to the simple code bellow, starting by ordering my values for the Individuals :
Individuals <- factor(Individuals,levels=Individuals[order(Pn)])
dotchart(Pn,label=Individuals,color=Groups)
The issue is that I only have 9 colors on this plot (so I lost information somehow) and I can't manage to find a way to apply manually one color per group.
I've also try to use the ggplot2 package by reading it could give nice looking things. In that case I can't manage to order properly the Individuals (the previous sorting doesn't seem to have any effect here), plus I end up with only different type of blue for the group representation which is not an efficient way to represent the information given by my data set. The plot I get is accessible here and I used the following code:
ggplot(data=gps)+geom_point(mapping=aes(x=Individuals, y=Pn, color=Groups))
I apologize if this question seems redundant but I couldn't figure a solution on my own, even following some answer given to others...
Thank you in advance!
EDIT: Using the RColorBrewer as suggested bellow sorted out the issue with the colors when I use the ggplot2 package.
I believe you are looking for the scale_color_manual() function within ggplot2. You didn't provide a reproducible example, but try something along the lines of this:
ggplot(data=gps, mapping=aes(x=Individuals, y=Pn, color=Groups))+
geom_point() +
scale_color_manual(values = c('GROUP1' = 'color_value_1',
'GROUP2' = 'color_value_2',
'GROUP3' = 'color_value_3'))
Replace GROUPX with the values inside your Group column, and replace color_value_x with whatever colors you want to use.
A good resource for further learning about ggplot2 is chapter 3 of R For Data Science, which you can read here: http://r4ds.had.co.nz/data-visualisation.html
I can't be sure without looking at your data, but it looks like Groups may be a numeric value. Try this:
gps$Groups <- as.factor(gps$Groups)
library(RColorBrewer)
ggplot(data=gps)+
geom_point(mapping=aes(x=Individuals, y=Pn, color=Groups))+
scale_colour_brewer(palette = "Set1")

External node color in Gephi

I'm trying to create a graph in Gephi. This graph is undirected and has over 100 nodes. I would like to color the nodes in this graph according to my convenience. Say I'd like to color the nodes in 9 different colors. For doing this, I downloaded a plugin to Gephi which may be found here.
Though the plugin works, I still have to go and enter the color value for every single node manually. There doesn't seem to be a way to do this programatically. And I'd have to create about 10 such graphs, so that means a lot of manual labor.
Can someone help me out with this problem? Does someone know a better way to have custom colors for each node generated programatically? At this point, I'm generating a .gdf file, the format looks something like this.
I also know that Gephi is quite buggy, is there any other graph visualization software that I can use? Out of the other usual things that one does to the graph, I definitely want the capability to set edge weights. In other words, I'd like to make the edges thicker if the edge weight is more and vice-versa.
I can't use D3 coz I don't know Javascript. I looked into using GraphViz but it seems like it requires a lot of manual manipulation of the graph file. I'd like to have something that I'm able to generate programatically.
What seems to be working is to add a column named color VARCHAR where you add the color hex value prepended with the # sign and no quotes.
Example:
nodedef> name,label,color VARCHAR
a,"Apple",#00ffdd
b,"Banana",#00ddff
c,"Cherry",#dd00ff
d,"Did it!",#0012ca
e,"Ed 209",#121212
edgedef> node1,node2,weight
a,b,2
b,c,30
b,d,0.4
d,e,200
Edit:
For a more informed answer take a look at the Gephi documentation. The color values in the link are rgb triples but I tried with hex and it worked

Mapping variable values to colors in gvisLineChart?

I'm looking for the equivalent of:
ggplot(df,aes(x=date,y=var1,**group=col1,colour=col1**))+geom_line()
in the googleVis package.
Anyone knows how to do this? I only found examples of differently colored lines if they are mapping different columns from the dataframe.
thanks!
#mtoto, I hope my answer here on ggplot2 equivalent of 'factorization or categorization' in googleVis in R can help. Have you taken a look?
Using roles you can specify specific styles for your data. It involves adding another column with the style detail. So if plotting varx, you need to add the column varx.style where you will set the colors.
I do not know ggplot well enough to know if this is the exact fit of what you want, but please take a look at my figures and links in that answer.

How to code edge attributes as vertex attributes using igraph in R

I am graphing a network and trying to color the vertices using non-overlapping attributes. I want my network diagram to be colored according to different attributes. In this example, if the first three letters of ID 2 are equal to U 50 or U 51, I want this to show up as red. I have 5 attributes I want this graph coded by and any observations that don't fall into one of the categories should be coded in a default color. In this way I will be able to see the intensity of these attributes and better communicate this to other people. So far, I have been unable to get the code to work using a variety of different coding methods. First I tried to create a new variable that assigned the correct attribute to each observation before converting it into an i graph object.
anon.nd$vertexcolor[substr(anon.nd$ID2,1,3)=="U50" | substr(anon.nd$ID2,1,3)=="U51"]<-"O"
anon.nd$vertexcolor[substr(anon.nd$ID2,1,3)=="U54" | substr(anon.nd$ID2,1,3)=="U55"]<-"P"
anon.nd$vertexcolor[anon.nd$INT.type=="K1"]<-"INT.NB"
anon.nd$vertexcolor[anon.nd$Country=="L12"]<-"UK"
anon.nd$vertexcolor[anon.nd$ID2=="U769"]<-"OBL"`
I then specified the colors I wanted to assign to each each attribute. I used the get vertex attribute code and filled in the appropriate colors.
anon.nd1<-graph.data.frame(anon.nd)
vertex_colors=get.vertex.attribute(anon.nd1,"vertexcolor")
colors=c('azure3', 'firebrick1', 'orange1', 'darkblue', 'darkolivegreen', 'gold')
vertex_colors[vertex_colors==0]=colors[1]
vertex_colors[vertex_colors==1]=colors[2]
vertex_colors[vertex_colors==2]=colors[3]
vertex_colors[vertex_colors==3]=colors[4]
vertex_colors[vertex_colors==4]=colors[5]
vertex_colors[vertex_colors==5]=colors[6]
I tried this same method using just:
vertex_colors<-vertex_colors+1
Then to plot, I changed my edge color to black, specified my layout, and change the size of my edges and vertices.
E(anon.nd1)$color="black"
nd.layout<-layout.fruchterman.reingold(anon.nd1)
plot(anon.nd1, layout=nd.layout, vertex.color=vertex_colors, vertex.size=2, edge.arrow.size=.01, vertex.label=NA)
Using this method, no color shows up on the vertices, not even the default color. Using a different method where I set the vertex attribute, I do a little better. The default color shows up, but the colors I want do not.
anon.nd2<-graph.data.frame(anon.nd)
V(anon.nd2)$colors<-"azure3"
V(anon.nd2)$colors[substr(anon.nd2$ID2,1,3)=="U50" | substr(anon.nd2$ID2,1,3)=="U51"]<-"firebrick1"
V(anon.nd2)$colors[substr(anon.nd2$ID2,1,3)=="U54" | substr(anon.nd2$ID2,1,3)=="U55"]<-"orange1"
V(anon.nd2)$colors[anon.nd2$Country=="L12"]<-"darkblue"
V(anon.nd2)$colors[anon.nd2$INT.type=="K1"]<-"darkolivegreen"
V(anon.nd2)$colors[anon.nd2$ID2=="U769"]<-"gold"
E(anon.nd2)$color<-"black"
nd.layout<-layout.fruchterman.reingold(anon.nd2)
windows(width=20, height=16)
plot(anon.nd2, layout=nd.layout, vertex.size=2, edge.arrow.size=.01, vertex.label=NA, vertex.color="vertex_colors")
I think the problem might be that I am trying to code vertex color using multiple (non-overlapping) edge attributes. But I don't know how to convert and edge attribute into a vertex attribute. I also don't know if there is some other, unidentified problem with my code.
Here is the link to my data is copied below as well as a link to my full code file which has one or two other methods I tried using to solve this problem. Any help would be much appreciated!
Data
And here is an R file with my code, which is also above: R-file
I think you are messing up your vertex_color vector, have a look at it with head().
anon.nd$vertexcolor[anon.nd$INT.type=="K1"]<-"INT.NB"
vertex_colors[vertex_colors==0]=colors[1]
You first assign a string and then compare with numbers, so non of them should be true.
plot(anon.nd2, layout=nd.layout, vertex.size=2, edge.arrow.size=.01, vertex.label=NA, vertex.color="vertex_colors")
This contains a typo and returns an error for me since "vertex_colors" isn't a colour name.
Last but not least, does
plot(anon.nd2, vertex.color=colors)
or
plot(anon.nd2, vertex.color=1:8)
result in a colourful plots? If yes, the vertex_colors vector is your problem, if not something else is.

Resources