I am trying to populate a single column stacked bar chart. It is just a sum of one value stacked over the other i.e. the sum of 'LB' experiments stacked over the 'Random' experiments.
Since I need to give a dimension value to the chart I have assumed a Dim variable with 1 as its value for both lb and random.
I am getting the above described data using the following code:
d3.csv("file:///D:/Optus/LARS T&L/Dashboard/html/dummy2.csv",function(error, experiments) {
var ndx = crossfilter(experiments),
rDim = ndx.dimension(function(d) {return d.Dim;});
var lb = rDim.group().reduceSum(function(d){return d.LBRandom=="LB"?d.Contacted:0;});
var ran = rDim.group().reduceSum(function(d){return d.LBRandom=="Random"?d.Contacted:0;});
Although when I am trying to plot this data, the browser only displays the the axis and no data is plotted:
Code for plotting:
chart
.width(768)
.height(480)
.x(d3.scale.ordinal())
.y(d3.scale.linear().domain([0,200000]))
.brushOn(false)
.dimension(rDim)
.group(lb)
.stack(ran)
.render();
});
Can anyone help me out with this? It's my 1st day working with d3, dc & crossfilters libraries.
Thanks!
Related
I am trying to plot two series (each has 2,000 points) using Plots.plot function in Julia 1.7.3.
When drawing the line plot, Julia displays a weird line that goes from an end of the line to the other across the plane as above. There is a strange orange diagonal, and there's no data point on that line. Does anyone know if this is a bug, or is there any error with my code?
Em_mu = [a_grid.+Es[1] res.mu[:,1]]
Unem_mu = [a_grid.+Es[2] res.mu[:,2]]
Em_dat = DataFrame(wealth = Em_mu[:,1], density1 = Em_mu[:,2])
Unem_dat = DataFrame(wealth = Unem_mu[:,1], density2 = Unem_mu[:,2])
wealth_mat = outerjoin(Em_dat, Unem_dat, on=:wealth)
replace!(wealth_mat.density1, missing => 0)
replace!(wealth_mat.density2, missing => 0)
disallowmissing!(wealth_mat)
wealth_mat = Matrix(wealth_mat)
Plots.plot(wealth_mat[:,1], wealth_mat[:,2:3], title = "Distribution")
It looks like your second series is not sorted by its x values. The line plot connects data points with a line so if it's not sorted you get weird lines like that.
I have the following dataset:
db1.1 <- data.frame(Status1.1 = rep(c("Completed", "Ongoing"), each=9),code1.1= rep(c(1:9), times=2), nProj1.1 = c(-24,-2,-17,-59,-1,-12,-6,0,0,0,2,3,5,0,2,0,1,1))
With this dataset, I build a graphic very similar to this one (code1.1 is the x axis, nProj1.1 is the y axis, and Status1.1 gives the two different grey tones):
I used this code to build the graphic:
ggplot(db1.1, aes(x=code1.1, y=nProj1.1, fill=Status1.1)) + geom_bar(stat="identity", position="identity")+coord_flip()+geom_hline(yintercept = 0, size=1)
However, I want to add a new variable/overlap a graphic, to obtain the following result:
Basically, it is the same as the one above but with values over the grey bars, with the dashed lines.
I have a new dataset that should correspond to the bars with dashed lines, with the same variables:
db1.2 <- data.frame(Status1.2 = rep(c("Completed", "Ongoing"), each=9),code1.2= rep(c(1:9), times=2), nProj1.2 = c(0,0,-14,-43,-1,-10,-5,0,0,0,2,3,5,0,1,0,0,1)) # manter assim, que já atribui a classe a cada variavel; ex.: factor, num, int, etc
I tried following this question: R-stacked-grouped barplot with different fill in R , but I didn't manage yet to make it work. I can also group both datasets and create a new binary variable, but I am not sure if that would help.
Does anyone know how can I make this kind of graph?
I am trying to plot FEVD (forecast error variance decomposition) for my VAR analysis. As you can see on the image, the legend screws up the graph and information. as this is an automatically created legend, I don’t know how to reposition it. I do not know much yet about plotting in R.
The only code i use to get this is :
library(vars)
var <- VAR(varTable2 , p=4 , type = "both")
plot(fevd(var, n.ahead = 10 ))
Thanks in advance
Legends do not resize well in R. You have to set your plotting window first and then chart your data.
Here's how to do it in Windows. win.graph opens a blank plotting window of the specified width. In Unix/Linux, you should look at X11() and in Mac, at quartz(). You might also consider shorter variable names.
library(vars)
data(Canada)
colnames(Canada) <-c("Long column name1","Long column name2","Long column name3","Long column name4")
var <- VAR(Canada , p=4 , type = "both")
win.graph(width=13,height=8)
plot(fevd(var, n.ahead = 10 ))
I have a bar chart where I want to show the value of the bar above each bar. However, using showValues results in the plot not working. Any ideas?
data2plot <-data.frame(Status=c("Open","Closed","Blocked"),Count=c(200,300,400))
a <- nPlot(Count ~ Status, data = data2plot, type = "multiBarChart")
a$chart(showValues=TRUE)
a
I'm using nplot, the nvd3 version. I'm open to changing to something else if I need to.
You can change type to discreteBarChart. To format the values displayed, you can use valueFormat, which takes a Javascript function and applies it to the values. Here is some info on d3.format function.
library(rCharts)
a <- nPlot(Count ~ Status, data = data2plot, type = "discreteBarChart")
a$chart(showValues=TRUE)
a$chart(valueFormat="#!d3.format('d')!#")
a
I have a dataset which has multiple longitude and latitude of different places in the UK. I am trying to use those figured to create multiple pie charts on the map. Whats essential is just making a pie chart on the map. NOTE: I can make a single pie chart if i hardcode the latitude and longitude.
Code:
floating.pie(xpos = area$longditude, ypos = area$Latitude,x=1, radius=0.2, col="orange")
Area:
area <- sqlQuery(con, "SELECT top 3 geo.Latitude, geo.longditude FROM dbo.[Geography]")
The dataset is:
55.9500, 3.1833
54.8659, -2.3522
54.0167, 2.6333
53.5667, 1.2000
52.8311, 1.3278
52.5000, 1.8333
52.3555, -1.1743
51.5000, 51.5000
51.4833, 3.1833
51.3167, 0.5000
50.9600, -3.2200
The error i am getting is:
Warning messages:
1: In cos(t2p) * radius + xpos :
longer object length is not a multiple of shorter object length
2: In sin(t2p) * yradius + ypos :
longer object length is not a multiple of shorter object length
Note: Using all of the above code, i dont get seperate piecharts at all. not sure how to do this, help please.
As an example view
plotting pie graphs on map in ggplot
What you see in the webpaghe is what i want i ve got it working nearly, just need to know how to tell R to differentiate those values i provide using Area and to plot them correctly as a single pie chart.
I was able to plot multiple float pie charts, but I had to use an infamous for loop.
area1<-data.frame(Longitude = c(10,30, 50),
Latitude = c(5, 25, 50))
plot(0:100,type="n",main="Floating Pie test",xlab="",ylab="",axes=FALSE)
for(i in 1:length(area1$Longitude)){
floating.pie(xpos = area1$Longitude[i],
ypos = area1$Latitude[i],edges = 200, x=1, radius=10, col="orange")
}