geom bar for data in rows
I have a data.frame:
I would like to do barlike plot where I would visualize results from column Transaction for each name in rows (decreasingly or increasingly)
See also questions close to this topic

Marge a dataframe which is a matrix x*x with series or a dataframe x*1 or 1*x
I have a dataframe like the one shown in bottom and I want to add column which come from the series or another data frame in whihch first martix will have the first item in series for all of it is items : example below explain the idea
x  y  z  1 4  5  7 > I have 20 of them like this 2 3  2  2 3 4  4  1 and I have a datafram whihc is from (1,2,3,4,5,6, ... 20) I want to add one column to all these 20 matrixes in whihch the first matrix will have number one for all of the column example : x  y  z  Result  1 4  5  7  1 2 3  2  2  1 ...... first matrix 3 4  4  1  1 x  y  z  Result  1 4  5  7  20 2 3  2  2  20 ...... 20 matrix 3 4  4  1  20
I did using pandas but it is not working , this is my code for idx in range(len(d.keys())): df = conv(d[idx]) ## the 20 dataframes will be created for idy in fitness: dfx = Series(series[idy])# the sereis of range 20 dfx.to_frame() fx = pd.concat(dfx,df)

Setting a default value to an indexed pyomo parameter
I got a dataframe which looks like following:
>data x y Name A NaN 0 B 65,2 NaN C NaN 100
I create a pyomo SetObject
m.index
, for indexing a mutable pyomo ParameterObjectm.parameter_y
.m.index
:# code m.index = pyomo.Set( initialize=data.index.get_level_values(0).unique(), doc='Index Set') # output (Pdb) m.index.pprint() index : Index Set Dim=0, Dimen=1, Size=3, Domain=None, Ordered=False, Mutable=True, Bounds=None ['A', 'B', 'C']
m.parameter_y
:# code m.parameter_y = pyomo.Param( m.index, default=data['y'].values, mutable=True doc='Par y') # output (Pdb) m.parameter_y.pprint() parameter_y : Par y Size=3, Index=index, Domain=Any, Default=None, Mutable=True Key : Value A : [ 0 nan 100. ] B : [ 0 nan 100. ] C : [ 0 nan 100. ]
As you can see using
default=df['y'].values
, gets all the values of the columny
as a value of the parameter.How would I set the values of a mutable indexed pyomo ParameterObject if I wanted to expect following output?
(Pdb) m.parameter_y.pprint() parameter_y : Par y Size=3, Index=index, Domain=Any, Default=None, Mutable=True Key : Value A : [ 0 ] B : [ nan ] C : [ 100 ]
PS: Keep in mind this isn't the actual dataframe, indexset, or the parameter. So Answers like adding values somehow manually won't work in my case. What would work, some kind of a better valuegettingfunction from a dataframe, so that, I can set these values on that parameter as default.

Set does not return unique elements from list of alphanumeric tuples  why? (Python 3.6)
I am extracting data on cells from a pd.DataFrame above a certain value. I'm storing the index, column header and value in a tuple. These tuples then get appended to a list. The layout of the dataframe I'm taking the values from means I extract each element twice and I need to store each combination only once. From reading previous peoples efforts set(list) should give these unique elements but on a mock dataset which should produce the single result ('Pathway1','Pathway2', 0.6) it reports two permutations.
Does anyone know why set is not working in this case? I know the lists need to be identical and to my eye they are (even down to the type of each tuple component (string, string, float)). Out of desparation I tried coercing the float to a string with no improvement.
For completeness most of the code is given (simplied a bit). The block at the bottom is where the problem arises. Code follows:
#Import modules import numpy as np import pandas as pd #Define trial sets s1 = ["A", "B", "C", "D", "E"] s2 = ["A", "B", "C"] s3 = ["A", "B", "F"] s4 = ["A", "B", "G", "H", "I"] s5 = ["X", "Y", "Z"] slist = [s1,s2,s3,s4,s5] #Create an empty list to append results to result1 = [] #Calculate Jaccard index between every entry #This is computationally inefficient as most computations are performed twice to generate a full results matrix to make mapping easy. Making half a matrix is more complicated but would be possible within the loop. Empty values would still have to be coded for though so in terms of storage of the final results matrix I don't think there should be much difference for i in range(len(slist)): for j in range(len(slist)): result1.append(len(set(slist[i]).intersection(slist[j]))/len(set(slist[i]).union(slist[j]))) #Define result matrix dimensions shape = (len(slist), len(slist)) #Convert list to array for numpy rarray = np.array(result1) pathway_names = ["Pathway1", "Pathway2", "Pathway3", "Pathway4", "Pathway5"] dataframe = pd.DataFrame(data = rmatrix, index = pathway_names, columns = pathway_names) #List all pathways with Jaccard index > x unless PathwayName = PathwayName x = 0.5 temp =[] #A temporary list for holding lists of tuples which will contain permutations
The issue lies in:
for k in range(len(slist)): index = dataframe.index[dataframe.iloc[k]>x] for l in range(len(index)): if index[l] != dataframe.columns[k]: temp.append((index[l], dataframe.columns[k], dataframe.iloc[l,k])) print(set(temp))
The output I get from printing
temp
is{('Pathway1', 'Pathway2', 0.6), ('Pathway2', 'Pathway1', 0.6)}
But I require (in any order):
('Pathway1', 'Pathway2', 0.6)
Thanks for any help you can provide,
Angus

How can adjust for covariates in a cumulative incidence function in R
I initially thought this question was more suited for Crossvalidated, but I think it has more to do with (application in) R.
I wanted to produce cumulative incidence curves for a causespecific competingrisk analysis. This is a fairly straightforward process with the
cuminc
function from thecmprsk
package. I ran the following code:fit1=cuminc(ftime=time,fstatus=event,group=x,cencode=0)
where
group
is the dichotomous variable I want to produce separate lines for , andevent
is the event of interest (as in a causespecific hazard where the regression is modeled with the standardcoxph
function, the other events are censored).Now, I can easily plot this with the native
plot
function, or my preferredggcompetingrisks
function from thesurvminer
package.I want to account for other covariates I included in the
coxph
function (e.g. age, sex. However, I couldn't find a way yet of doing this and producing adjusted cumulative incidence curves for the events I am plotting. How can I do this? Is there a package that would help me adjust for other covariates when plotting cumulative incidence curves for competing risks?P.S. I read an article about this here, something about "inverse probability weighting"  however the examples are for SAS so it wasn't particularly helpful.

bar plot width and orders when on top of other bars
I have this plot
library(ggplot2) library(reshape) x = c("Band 1", "Band 2", "Band 3") y1 = c("1","2","3") y2 = c("2","3","4") to_plot < data.frame(x=x,y1=y1,y2=y2) melted<melt(to_plot, id="x") ggplot(melted,aes(x=x,y=value,fill=variable)) + geom_bar(stat="identity",position = "identity", alpha=.3 ,width = .3)
Is it possible to:
(1) make the width of variable = y1 be .3 and the variable = y2 be .5
(2) make variable = y1 always be the top bar
Thank you

How to make a line graph in R with specific independent variables in a column
I am looking to make a simple graph in ggplot with the following example data set. I want to plot the dependent variable 'wt' on the independent variable 'time'
This is the code I used to make the graph.
> ggplot(example_data, aes(x = time, y = wt)) + + geom_point() + + geom_smooth(method = lm, se = FALSE, fullrange = TRUE) structure(list(code = c(100, 100, 100, 101, 101, 101, 102, 102, 102), treatment = c(1, 1, 1, 2, 2, 2, 1, 1, 1), time = c(1, 2, 3, 1, 2, 3, 1, 2, 3), wt = c(80, 78, 76, 75, 74, 74, 78, 74, 72), wc = c(90, 89, 87, 92, 91, 90, 89, 86, 84)), .Names = c("code", "treatment", "time", "wt", "wc"), row.names = c(NA, 9L), class = c("tbl_df", "tbl", "data.frame"))
I would like to make a graph that picks 'wt' only for time 1 and time 2. How do I do this?

Illustrate Tower of Hanoi with ASCII
I am familiar with the recursive function of the Hanoi Tower.
Now I need to visualize the movements, representing the discs with asterisks (I guess disc number = number of asterisks makes sense).
Does anyone have a hint or example for how to draw the disc movements step by step using just
* *** *** ***** ***** *   ...
or similar?
This is the sample code my professor provided and I do understand how the recursion works. But after one lecture in Python I must say that I'm somewhat overwhelmed with the visualization task.
def hanoi(n, p1, p2, p3): if n==1: print("move from %d to %d" %(p1, p3)) else: hanoi(n1, p1, p3, p2) print("move from %d to %d " %(p1, p3)) hanoi(n1, p2, p1, p3) return if __name__=='__main__': j=int(input('Input the number of disk to be moved:\n')) print('Number of disk to be move is %d \n'%j) hanoi(j, 1, 2, 3)
Help would be much appreciated!

How can I create a plot that overlays point data with an unequally spaced matrix plot?
I want to create a plot similar to the attached image where point data is laid over a matrix color plot:
I have
x
andy
data. I have then created matrixxy_bincount
by counting the number of points inx
andy
that lie within my xy bin combinations. The bin width are not uniform as can be seen in the attached fig.Would it be easier to create this plot in R, Matlab or Python?
Thanks for the help!
x<c(2.56481, 2.11009, 1.72927, 1.47803, 1.74279, 3.29555, 3.66061, 2.63349, 2.43808, 2.13, 3.09267, 2.3555, 2.48811, 4.05344, 3.38401, 2.69907, 2.26378, 2.71978) y<c(1.26044, 13.6098, 0.710325, 4.27657, 11.1908, 7.2431, 3.19167, 20.7423, 10.009, 32.12, 42.6192, 13.9598, 0.412724, 20.3846, 6.97259, 14.2046, 8.30859, 0.0386572) xylabels<c("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R") xy_bincount<matrix(c(0, 0, 0, 6, 0, 0, 6, 12, 0, 0, 24, 6, 0, 0, 29, 0, 0, 0, 12, 6),nrow = 5, ncol = 4, byrow = TRUE)

How to add a value in a cell Google table chart
I've been looking for a way to add a value in a specific cell in a google chart table but i couldnt find how if anyone has an answer i would be pleased !