I have created a sample data set for this quesition
import pandas as pd
from pandas import DataFrame
import seaborn as sns
import numpy as np
sex = np.array(['Male','Female'])
marker1 = np.array(['Absent','Present'])
marker2 = np.array(['Absent','Present'])
sample1 = np.random.randint(0,2,100)
sample2 = np.random.randint(0,2,100)
sample3 = np.random.randint(0,2,100)
df=pd.concat([pd.Series(sex.take(sample1),dtype='category'),pd.Series(marker1.take(sample2),dtype='category'),pd.Series(marker2.take(sample3),dtype='category')],axis=1)
df.rename(columns={0:'Sex',1:'Marker1',2:'Marker2'},inplace=True)
fig =sns.FacetGrid(data=df,col='Sex',hue='Marker2',palette='Set1',size=4,aspect=1).map(sns.countplot,'Marker1',order=df.Marker1.unique()).add_legend()
The plot this code creates is a stacked plot What I want to create is a dodge plot (from R). How can I modify this code so that I can see a side by side comparison of Marker2 presence?
factorplot
gives me an TypeError. The error isTypeError: object of type 'NoneType' has no len()
– A Gorefactorplot
by using the codesns.factorplot(x='Marker1',col='Sex',hue='Marker2',palette='Set1',kind='count')
. Thanks for your help! But, the question still remains as to why I wasn't able to use the commandsns.FacetGrid()
. – A GoreFacetGrid
just plots different hue layers on top of each other. – mwaskom